Java the little console game won't repeat?
- by Jony Kale
Okay, what I have so far is:
You enter the game, and write "spin" to the console.
Program will enter the while loop.
In the while loop, if entered int is -1, return to the back (Set console input back to "", and let the user select what game he would like to play).
Problem:
Instead of going back, and selecting "spin" again, the program exits?
Why is it happening? How can I fix this?
private static Scanner console = new Scanner(System.in);
private static Spin spin = new Spin();
private static String inputS = "";
private static int inputI = 0;
private static String[] gamesArray = new String[] {"spin", "tof"};
private static boolean spinWheel = false;
private static boolean tof = false;
public static void main (String[] args) {
if (inputS.equals("")) {
System.out.println("Welcome to the system!");
System.out.print("Please select a game: ");
inputS = console.nextLine();
}
while (inputS.equals("spin")) {
System.out.println("Welcome to the spin game! Please write 1 to spin. and -1 to exit back");
inputI = console.nextInt();
switch (inputI) {
case 1:
break;
case -1:
inputI = 0;
inputS = "";
break;
}
}
}