So I have this code where the user enters a random number from 0 to 9 and has to guess the number but I want to limit the users trials to 4 once he guessed wrong 4 times the system stops and displays a message "you exceeded your allowed trials" this is my code so far:
public static void main(String[] args) {
// TODO Auto-generated method stub
int nb,x;
int count= 0;
Scanner inp= new Scanner(System.in);
nb= (int)(Math.random()*10);
System.out.print("Guess the number between 0 and 9");
x=inp.nextInt();
while(x!= nb) {
if(x>nb) System.out.println("Lesser");
else if (x<nb) System.out.println("Bigger");
System.out.println("Try another Number");
x=inp.nextInt();
count++;
}
System.out.println("Found!!");
System.out.println("Number of Guesses:" +count);
inp.close();
}