gpt4 book ai didi

java - 使用脚本获取 'not a statement' 错误

转载 作者:行者123 更新时间:2023-11-30 07:05:47 24 4
gpt4 key购买 nike

我正在尝试弄清楚为什么这个脚本不起作用。我正在尝试创建一个脚本,让我生成一个随机数,当程序完成时,我可以选择是否重新运行它。但是每次我编译它时,我都会得到一个“不是声明”的错误。即使我删除 String continue 它仍然给我这个错误。

import java.util.*;

public class Loopers {
public static void main(String[] args) {
String
continue = "yes";
Scanner getInput = new Scanner(System.in);
while (
continue.equals("yes") ) {

Random r = new Random();
int numOfRandoms;
System.out.println("Enter a number");
numOfRandoms = getInput.nextInt();

int[] randomNum = new int[100];

for (int x = 1; x < numOfRandoms; x++) {
randomNum[x] = r.nextInt(100);
System.out.println(randomNum[x]);
}
System.out.println();
System.out.println("Do you wish to run the program again? Yes or No.");
getInput.nextLine();
continue = getInput.nextLine();
}

}
}

最佳答案

这是无效代码,continue 是 Java 中的关键字,您不能这样命名变量:

String continue = "yes";

尝试将其重命名为其他名称,例如:

String cont = "yes";

关于java - 使用脚本获取 'not a statement' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26347871/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com