我试图开发一个程序,其中随机数生成器将生成一个数字,然后根据选择的数字,将打印预定义数组的成员之一。(我希望在数组内部调用该方法索引号)
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)
有人可以告诉我这个程序的主要问题是什么。
非常感谢您提前回答