I'm new to programming and while working on the Head First Java book I wanted to make a simple program, but there are some points I can't do. What I want the program to do is keep an integer number between 0 and 100 randomly and the user tries to find it. If the user finds the number, congratulations will appear on the screen. If not, it will ask for a new prediction. The code I wrote is below:
package Intro;
import java.util.Scanner;
public class GuessingGame {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Please enter a number: ");
int prediction = input.nextInt();
int number = (int) (Math.random());
if (number==prediction) {
System.out.println("Congratulations!");
}
else {
System.out.println("Wrong answer! Try a new number: ");
}
}
}
The point I stuck is that I can't make the randomly stored number integer and a number between 0 and 100. Another point is that if the answer is wrong, the program does not want a new prediction.