我正在尝试制作一个 12 x 12 表,其中包含不同的随机字母,但用户可以选择它是否包含 4 个不同的字母,3 或 2 ......但是我收到一个错误,字符串不能是解决了,我不知道为什么...请帮助...
import java.util.Scanner;
import java.util.Arrays;
import java.util.Random;
public class PlayingArea {
public static void main(String[] args){
int N = letters.length();//error here "letters cannot be resolved"
Random r = new Random();
Scanner input = new Scanner(System.in);
System.out.println("How many regions would you like (2- 4)");
int region = input.nextInt();
if (region == 4){
String letters= "EFGH";
}
if (region == 3){
String letters= "EFG";
}
else if (region == 2){
String letters= "EF";
}
else { System.out.println("You inputed a wrong value, try again...");
}
char [][] letter = new char[12][12];
for (int j = 0; j < letter.length; j++){
for(int i=0; i < letter.length; i++) {
letter[i][j] = letters.charAt(r.nextInt(N)) ;
}
}
for (char[] letterRow : letter)
System.out.println(Arrays.toString(letterRow)); //error here "letters cannot be resolved"
}
}