嗨,我是Java SE開發新手。我試圖做一個7次嘗試的猜謎遊戲,這裏是我的不完整(應該有錯誤)。每當我試圖調試任何行消息「淨豆沒有變量顯示,因爲沒有當前線程」顯示。請給我解決方案如何擺脫這條消息,我在我的代碼中犯了什麼錯誤和什麼都可以code.Here的可能的改進是代碼:沒有變量顯示,因爲沒有當前線程
import java.util.Random;
import java.util.*;
public class JavaApplication3 {
public static void main(String[] args) {
///////////////////part1 random number generation/////////////////////////////////////
int rnd = (int) (Math.random() * 5) + 1;//so that the position can be started after 0
System.out.println("Welcome to the Random Number guess Game!\n");
/////////////////////////part 2 guess it is if that number////////////////////////////
int number, attempt = 0;
Scanner sc = new Scanner(System.in);///////create scanner object
System.out.print("what did you guess?:");
number = sc.nextInt();
System.out.println("you guessed:" + number);
do {
if (number > rnd || number < rnd) {
System.out.println("Guess is incorrect");
}
// System.out.println("generated number was:"+rnd);
System.out.println("generated number was not right");
System.out.println("try again");
attempt++;
} while (number != rnd && attempt < 7);
if (number == rnd) {
System.out.println("Guess is correct");
} else {
System.out.println("Incorrect 7 attempts");
}
}
}
只是爲了確保,當程序因打斷點而停止時,您仍然看到此消息?如果程序當前正在執行(例如,未被調試器暫停),則無法檢查變量。 – Patashu