package src.test;
import java.util.Random;
public class test32 {
public static void main(String[] args) {
String[] ABC = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
Random r = new Random();
int math = r.nextInt(10);
String yanzhenma = "";
for (int i = 0; i < 4; i++) {
int A = r.nextInt(ABC.length) - 1;
yanzhenma += ABC[A];
}
yanzhenma += math;
System.out.println(yanzhenma);
}
}
运行这个的时候会出现Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 52 at src.test.test32.main(test32.java:13)
在cmd里面运行也会出错
咋办啊
import java.util.Random;
public class test32 {
public static void main(String[] args) {
String[] ABC = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
Random r = new Random();
int math = r.nextInt(10);
String yanzhenma = "";
for (int i = 0; i < 4; i++) {
int A = r.nextInt(ABC.length) - 1;
yanzhenma += ABC[A];
}
yanzhenma += math;
System.out.println(yanzhenma);
}
}
运行这个的时候会出现Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 52 at src.test.test32.main(test32.java:13)
在cmd里面运行也会出错
咋办啊