Code
package com.company;
import java.util.Random;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
Random random = new Random();
boolean condition1 = true;
boolean condition2 = true;
while (condition1) {
int intRandom = random.nextInt(10);
System.out.println("Enter 1 to play, or 2 to quit!!");
int option = scan.nextInt();
switch (option) {
case 1:
while (condition2) {
System.out.println("Guess which number has been chosen from 0-9: ");
int guess = scan.nextInt();
if (guess == intRandom) {
System.out.println("Your guess was correct!! Number was " + intRandom);
break;
} else {
System.out.println("You chose wrong, keep guessing!!");
}
}
case 2:
condition1 = false;
break;
}
}
}
}
So with:
case 2:
condition1 = false;
^it does exit the program when you press 2 as it should BUT with condition1 = false, it doesn't relooop the programing after you guess the correct number it just exits program
and without condition 1 = false in case 2
it does reloop the program prompting user to play again or exit program, But pressing 2 doesn't work exiting program
Been stumped on this for hours, kinda stumped, plz help. Thanks guys. Hopefully all this makes sense.