嗨,我是 Java SE 开发的新手。我正在尝试进行 7 次猜谜游戏,这是我的不完整(应该是错误的)。每当我尝试调试任何行时,都会显示消息“net beans no variables to display because there is no current thread”。请给我解决方案,我怎样才能摆脱这个消息以及我在代码中犯了什么错误和什么是可能的代码改进。这是代码:
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");
}
}
}