Java the little console game won't repeat?

Posted by Jony Kale on Stack Overflow See other posts from Stack Overflow or by Jony Kale
Published on 2013-06-24T22:18:02Z Indexed on 2013/06/24 22:21 UTC
Read the original article Hit count: 107

Filed under:

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;
            }
        }
    }

© Stack Overflow or respective owner

Related posts about java