#Return to menu...

5 messages · Page 1 of 1 (latest)

eternal estuary
#

Hi! I am trying to learn Java and I got stuck to this step.
All I'm trying to do is that after making the choice I want the user to be sent again to the main menu.

A piece of the code is ``` System.out.println("\nYou got tired. Go back home\n1. Ok\n");

            Scanner scanner = new Scanner(System.in);
            int choice = scanner.nextInt();

            if (choice == 1) {
                //loopmenu();
            } else {
                System.out.println("You really have to go home -_- ");
            } ```

I am trying basically to choose 1 and go back here --> check comments

delicate shardBOT
#

This post has been reserved for your question.

Hey @eternal estuary! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

eternal estuary
#
>             // An infinite loop to keep the game running until the user chooses to exit
>             while (true) {
>                 // Display the main menu
> 
>                 System.out.println("\nMenu:\n1. Gather resources\n2. Craft\n3. View inventory\n4. Skills\n5. Study\n6. Sleep \n7. Exit");
                randomlegevent();
                randomwolvesevent();
                lootingevent();
                System.out.println("Day " + day);
                System.out.println("Health: " + health + "%");
                System.out.print("Choose an option: ");
                // Get the user's choice from the menu
                int choice = sc.nextInt();
                sc.nextLine();
                switch (choice) {
                    case 1 -> gatherResources();  // Call the gatherResources method if the user chooses to gather resources
                    case 2 -> craft();           // Call the craft method if the user chooses to craft items
                    case 3 -> viewInventory();   // Call the viewInventory method if the user chooses to view their inventory
                    case 4 -> viewSkills();     // Call the viewSkills method if the user chooses to view their skills
                    case 5 -> study();           // Call the study method if the user chooses to study
                    case 6 -> sleep();           // Call the sleep method taking the player to a new day.
                    case 7 -> System.exit(0);   // Exit the program if the user chooses to exit
                    default -> System.out.println("Invalid choice.");  // Display an error message if the user inputs an invalid choice
                }
            }``` I thought I can simply call main() but looks like this is going to be more difficult .
rich minnow
#

What’s the issue you run into?