所以我想做一个带有测验等的小程序(不会粘贴整个代码,因为它有 300 行基本内容),并且我想要一个为我重复赌博游戏的 boolean 值,所以当我开始该行:
String PlayAgain = input.nextLine();
我收到错误:无法解析符号“输入”。
小游戏的代码在这里:
enter boolean InGame = true;
while (InGame == true);
System.out.println("Glückspiel: Wer näher an der zufälligen Zahl ist gewinnt! 1-100");
System.out.println("Spieler Eins");
double playerOne = scan.nextDouble();
System.out.println("Spieler Zwei");
double playerTwo = scan.nextDouble();
double randomValue = Math.random() * 100.0;
// Math.abs() ist eine Methode die den Betrag einer Zahl zurueck gibt.
double spacingOne = Math.abs(playerOne - randomValue);
double spacingTwo = Math.abs(playerTwo - randomValue);
System.out.println("Die Random Zahl war " + randomValue);
if (spacingOne < spacingTwo) {
System.out.println("Spieler Eins hat gewonnen!");
}
if (spacingOne > spacingTwo) {
System.out.println("Spieler Zwei hat gewonnen!");
}
if (spacingOne == spacingTwo) {
System.out.println("Unentschieden!");
}
System.out.println("Wenn du nochmal spielen willst schreibe 'ja' wenn nicht 'nein'");
String PlayAgain = input.nextLine();
if (PlayAgain == "Ja");
你能帮我吗?
最佳答案
也许你错过了
扫描仪输入 = new Scanner(System.in)
?
或将输入
更改为扫描
String PlayAgain = scan.nextLine();
关于java - 无法解析符号 'input' JAVA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43098411/