我試圖開發程序,其中,隨機數生成器將建立一個號碼,然後根據選擇,一個預先定義的陣列的構件中的一個將被打印的數量。(我想被內調用的方法數組索引號)在java中這個隨機int生成器有什麼問題?
import java.util.Random;
import java.util.Scanner;
public class Testing{
public static void main(String args[]){
public static int calculatew() {
Random generator = new Random();
int number1 = generator.nextInt(3);
}
String array1 [] = new String[4];
array1[1]="Tom";
array1[2]="Jerry";
array1[3]="Mike";
array1[0]="Dustin";
System.out.println("the very first name is "+array1[calculatew]+" The second name is "+array1[calculatew]+" the third accodental name is "+array1[calculatew]+" and the final random name is "+array1[calculatew]+".");
}
}
當程序被編譯它給我回了以下錯誤:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Syntax error on token(s), misplaced construct(s)
Syntax error on token "int", @ expected
calculatew cannot be resolved to a variable
calculatew cannot be resolved to a variable
calculatew cannot be resolved to a variable
calculatew cannot be resolved to a variable
at Testing.main(Testing.java:7)
會有人告訴我的主要問題是這一計劃的內容。
非常感謝你對你的答案提前
之一的嚴格要求有關縮進你的代碼的好處是,你的錯誤變得更加容易察覺。這是一個暗示。 – goat