主类:
public class ECONAPP2 {
static Scanner input= new Scanner(System.in);
static int score = 0;
static ArrayList<Integer> usedArray = new ArrayList<Integer>();
public static void main(String[] args){
app();
arrayContents();
}
public static void arrayContents() {
usedArray.add(2);
usedArray.add(1);
}
应用程序()方法:
public static void app() {
Random generator = new Random ();
int randomNumber = generator.nextInt(usedArray.size());
System.out.println(randomNumber);
if (randomNumber == 2) {
score();
question2();
usedArray.remove(2);
app();
}
if (randomNumber == 1) {
score();
question1();
usedArray.remove(1);
app();
}
收到此错误:
Exception in thread "main" java.lang.IllegalArgumentException: n must be positive
at java.util.Random.nextInt(Random.java:250)
at ECONAPP2.app(ECONAPP2.java:65)
at ECONAPP2.main(ECONAPP2.java:10)
无法弄清楚这意味着什么以及 n 代表什么?