(16) 6. You want to write a Java application that creates a while loop that runs until the user enters a 0 as input. Each time the while loop runs, it displays a menu of three choices as will be shown in the sample run below. When the program reads in the user's choice, that choice should be read in as a String called choiceStr. Then, choiceStr should be converted into an int called choice by using the code below: int choice = Integer.parseInt(choiceStr); If the user enters a 1 for choice == 1, the program will print "Choice 1" to the screen. If the user enters a 2 for choice == 2, the program will print "Choice 2" to the screen. Here is a sample run: 0 - to quit 1 to print Choice 1 2 to print Choice 2 Enter choice: 1 Choice 1 0 - to quit 1 to print 2 to print Enter choice: 1 Choice 1 Choice 2 Choice 1 0 - to quit 1 to print Choice 1 2 to print Choice 2 Enter choice: 2 Choice 2 0 - to quit 1 to print Choice 1 2 to print Choice 2 Enter choice: 0

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 20PE
icon
Related questions
Question
(16) 6. You want to write a Java application that creates a while loop that runs until the user enters a 0 as input. Each time the while loop runs, it displays a menu of three choices as will be shown in the sample run
below. When the program reads in the user's choice, that choice should be read in as a String called choiceStr. Then, choiceStr should be converted into an int called choice by using the code below:
int choice Integer.parseInt(choiceStr);
If the user enters a 1 for choice == 1, the program will print "Choice 1" to the screen. If the user enters a 2 for choice == 2, the program will print "Choice 2" to the screen. Here is a sample run:
0 - to quit
1
to print Choice 1
2 to print Choice 2
Enter choice: 1
Choice 1
0 - to quit
1 to print
Choice 1
2 to print Choice 2
Enter choice: 1
Choice 1
0
to quit
1
to print Choice 1
2 to print Choice 2
Enter choice: 2
Choice 2
0 - to quit
1 to print Choice 1
2 to print Choice 2
Enter choice: 0
Transcribed Image Text:(16) 6. You want to write a Java application that creates a while loop that runs until the user enters a 0 as input. Each time the while loop runs, it displays a menu of three choices as will be shown in the sample run below. When the program reads in the user's choice, that choice should be read in as a String called choiceStr. Then, choiceStr should be converted into an int called choice by using the code below: int choice Integer.parseInt(choiceStr); If the user enters a 1 for choice == 1, the program will print "Choice 1" to the screen. If the user enters a 2 for choice == 2, the program will print "Choice 2" to the screen. Here is a sample run: 0 - to quit 1 to print Choice 1 2 to print Choice 2 Enter choice: 1 Choice 1 0 - to quit 1 to print Choice 1 2 to print Choice 2 Enter choice: 1 Choice 1 0 to quit 1 to print Choice 1 2 to print Choice 2 Enter choice: 2 Choice 2 0 - to quit 1 to print Choice 1 2 to print Choice 2 Enter choice: 0
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Types of Loop
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning