import java.util.Random;
import java.util.Scanner;
public class GuessingNumberGame {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
int numberDrawn = drawNumber();
// program your solution here. Do not touch the above lines!
int guessCount = 0;
while(true){
System.out.println("Guess a number: ");
int n = Integer.parseInt(reader.nextLine());
guessCount++;
if(n == numberDrawn) {
break;
} else if(n < numberDrawn) {
System.out.println("The number is lesser, guess made: " + guessCount);
} else if(n > numberDrawn) {
System.out.println("The number is greater, guess made: " + guessCount);
}
}
System.out.println("Congratulations, your guess is correct");
}
// DO NOT MODIFY THIS!
private static int drawNumber() {
return new Random().nextInt(101);
}
}
Hello, It seems random number generator is not working. The numbers I have checked and just cannot find what is wrong for the love of me.
If anyone can point out what I might not be seeing, It will be appreciated.
Thanks.
Aucun commentaire:
Enregistrer un commentaire