I'm new to java programming and was testing some of the stuff I learned in order to make a little guessing game. It works and you can run through it, but after you get the second number wrong, you aren't prompted telling you whether the number is lower or higher. Here is an example of the problem:
Guess a number, 1 through 100:
50
Guess higher!
75
75
Guess lower!
65
65
Guess lower!
And here is the code:
public static void main(String[] args) {
Random num = new Random();
Scanner scan = new Scanner(System.in);
int rand;
boolean test;
int rand2;
int guess = 0;
rand = num.nextInt(100);
System.out.println("Guess a number, 1 through 100: ");
while(test = true){
rand2 = scan.nextInt();
if(rand == rand2){
guess++;
if(guess < 19){
System.out.println("Thats the correct number! And it only took: " + guess + " tries");
}else{
System.out.println("It took you: " + guess + " tries to guess the number!");
}
}else if(rand < rand2){
System.out.println("Guess lower! ");
guess++;
rand2 = scan.nextInt();
}else if(rand > rand2){
System.out.println("Guess higher! ");
guess++;
rand2 = scan.nextInt();
}
}
}