Solution: Level Up the Java Menu App

This Java program is a menu-based console application that lets users choose different actions interactively. It uses the Scanner class for user input and the Random class for generating random numbers.

When the program runs, it repeatedly shows a main menu with five options:

  1. Greet: Displays a friendly welcome message.

  2. Tell a joke: Prints a simple programming-related joke.

  3. Show a random number: Generates and displays a random number between 1 and 100.

  4. Play the guessing game: Starts a small game where the user must guess a randomly chosen number between 1 and 10. The program gives hints like “Too low” or “Too high” until the correct number is guessed.

  5. Exit – Ends the program.

The program keeps looping until the user selects option 5. It also checks if the input is valid — if the user enters something other than a number, it shows an error message and asks again.

In summary, this code demonstrates how to:

  • Use loops for continuous interaction.

  • Handle user input safely.

  • Apply switch statements for menu options.

  • Use the Random class for generating unpredictable results.
    It’s a simple example of combining control structures, input handling, and randomization in a Java console app.

Solution: Level Up the Java Menu App

This Java program is a menu-based console application that lets users choose different actions interactively. It uses the Scanner class for user input and the Random class for generating random numbers.

When the program runs, it repeatedly shows a main menu with five options:

  1. Greet: Displays a friendly welcome message.

  2. Tell a joke: Prints a simple programming-related joke.

  3. Show a random number: Generates and displays a random number between 1 and 100.

  4. Play the guessing game: Starts a small game where the user must guess a randomly chosen number between 1 and 10. The program gives hints like “Too low” or “Too high” until the correct number is guessed.

  5. Exit – Ends the program.

The program keeps looping until the user selects option 5. It also checks if the input is valid — if the user enters something other than a number, it shows an error message and asks again.

In summary, this code demonstrates how to:

  • Use loops for continuous interaction.

  • Handle user input safely.

  • Apply switch statements for menu options.

  • Use the Random class for generating unpredictable results.
    It’s a simple example of combining control structures, input handling, and randomization in a Java console app.