我似乎不能跳過while循環,因爲我的代碼不明白我輸入了正確的數字。我的代碼有什麼問題?
import java.util.Scanner;
public class HelloWorld1{
static Scanner userInput = new Scanner(System.in);
static int randomNumbe
public static void main(String[] args){
System.out.println(randomNum());
int randomGuess = -1 ;
while(randomGuess != randomNum()){
System.out.println("Guess a number between 0 to 100");
randomGuess = userInput.nextInt();
}
System.out.println("Yes the random number is:" + randomGuess);
}
public static int randomNum(){
randomNumber = (int) (Math.random()*101);
return randomNumber;
}
}
你不打印任何地方的號碼。你在使用調試器嗎?因爲如果你能猜出一個沒有任何線索的隨機數,我認爲你有更好的職業追隨......換句話說:隨機數在每次迭代中都在變化。你怎麼知道這是對的? – Arc676