我对编码的所有知识都非常陌生,并且正在对Java进行一些基本的编码,并遇到“解析时文件到达末尾”错误,我尝试了我能找到的唯一解决方法(将所有方括号括起来),但无法解决
我查看了如何修复它,并尝试对其进行修复,并确保所有大括号都正确校正了相应的闭合大括号
import java.util.Random;
import java.util.Scanner;
public class GuessGame {
public static void main (String[] args) {
{
Random rand = new Random();
intNumberToGuess = rand.nextInt (100);
intNumberOfTries = 0;
Scanner input = new Scanner(System.in);
int guess;
boolean win = false;
while (win == false) {
System.out.println("Guess and Enter any number between 1 and 100:");
guess = input.nextint ();
numberoftries++;
if (guess == numberToGuess);
else if (guess < numberToGuess)
System.out.println("Guess Lower!");
else if (guess > numberToGuess)
System.out.println("Guess Higher!");
win = true;
}
System.out.println("You win");
System.out.println("The correct number was " + numberToGuess);
System.out.println("It took you" + numberOfTries + " tries!") ;
}
}
答案 0 :(得分:-1)
import java.util.Random;
import java.util.Scanner;
public class GuessGame {
public static void main (String[] args) {
{ //this opens a new block of code with its own scope. you surely did not mean to do this, remove it
Random rand = new Random();
intNumberToGuess = rand.nextInt (100);
intNumberOfTries = 0;
Scanner input = new Scanner(System.in);
int guess;
boolean win = false;
while (win == false) {
System.out.println("Guess and Enter any number between 1 and 100:");
guess = input.nextint ();
numberoftries++;
if (guess == numberToGuess)
;
else if (guess < numberToGuess)
System.out.println("Guess Lower!");
else if (guess > numberToGuess)
System.out.println("Guess Higher!");
win = true;
}
System.out.println("You win");
System.out.println("The correct number was " + numberToGuess);
System.out.println("It took you" + numberOfTries + " tries!") ;
}
} //this is just closing the main-function, not yet the class (but fix by removing the upper)