I need your help concerning my switch.
Here is an example:
1) I enter the choice 1
*****MENU*****
1) Start Play :
2) Exit :
Enter your choice : 1
2) I enter the number 4
You have 5 attemps.
Enter your number : 4
Bravo !
3) I Won !
I again want to play...
I enter the number 1 in the option 1.
Bravo !
*****MENU*****
1) Start Play :
2) Exit :
Enter your choice : 1
Here, I have a problem... I cannot enter in the option 1 and then play ???
I always have this:
Enter your choice : 1
Option 1 :
*****MENU*****
1) Start Play :
2) Exit :
Enter your choice :
I think my problem is in my case 1?
int choice_user = 0;
int number_to_search = 4;
int number_user = 0;
boolean number_found = false;
int attemps = 5;
do {
System.out.println("*****MENU*****");
System.out.println("1) Start Play : ");
System.out.println("2) Exit : ");
System.out.print("Enter your choice : ");
choice_user = sc.nextInt();
switch (choice_user) {
case 1:
System.out.println("Option 1 : ");
while (number_to_search > 0 && !number_found) {
System.out.println("You have " + attemps + " attemps.");
System.out.print("Enter your number : ");
number_user = sc.nextInt();
if (number_user > number_to_search) {
System.out.println("Smallest ! ");
} else if (number_user < number_to_search) {
System.out.println("Biggest ! ");
} else {
number_found = true;
System.out.println("Bravo ! ");
}
attemps--;
}
break;
default:
System.out.println("Exit...");
}
} while (choice_user != 2);
number_foundshould benumberFound.