-1
Java中的初學者在這裏。System.out.println - 語法錯誤
試圖找出爲什麼我得到最後兩個System.out.println語法錯誤。
我試着移動我的括號,但我最終得到了一個永無止境的循環。
我非常感謝您的幫助!
import java.util.Scanner;
public class GuessingGame
{
public static void main(String args [])
{
Scanner scan = new Scanner (System.in);
int random = (int) (Math.random()*20 +1);
int numberOfAttempts = 0;
boolean win = false;
while (win == false)
System.out.println("Guess the number (1 - 20)");
int guess = scan.nextInt();
numberOfAttempts++;
if (guess == random)
win = true;
else if (guess < random)
System.out.println("Your guess was low. Guess again.");
else
System.out.println("Your guess was high. Guess again.");
}
System.out.println("You guessed right! It took you guesses.");
System.out.println("Do you want to play again? (yes or no)");
}
您應該正確縮進代碼。什麼被認爲是「while」循環的主體?投票關閉印刷錯誤。 –
謝謝。我仍然試圖找出縮進問題。 while循環的主體應該是猜測遊戲執行的「猜數字」。 – CLTMedic
1.在/ if/while/method/switch/class /等中使用大括號。 2.計算你的大括號,每個開口大括號應該有一個大括號 –