Question: Write a Java program (name it InputSum YourName ) that prompts the user to enter positive integer numbers using a sentinel while loop. The program

Write a Java program (name it InputSumYourName) that prompts the user to enter positive integer numbers using a sentinel while loop. The program should accept integer inputs until the user enters the value -1 (negative one is the sentinel value that stops the while loop). After the user enters -1, the program should display the entered numbers followed by their sum as shown below. Notice that -1 is not part of the output. The program should ignore any other negative input and should continue to run.

Make sure the program validates each entered number before processing it as the user may enter negative numbers (other than the sentinel value -1).

Hint1: to remember/store the entered (good) positive values, you can concatenate them into a String (separated by comas) that you can output later on. Hint2: Scanners nextInt() will take an integer one-by-one, even all numbers entered at once in advance.

Design your program such that it allows the user to re-run the program with a different set of inputs in the same run.

Hint: You may need a loop for retrying

Document your code and organize and space out your outputs as shown below. The following are sample test data shows the input prompt and the output labels. Notice the user may enter one value per line. DO NOT read inputs as String type. The sample test data below assumes that the user enters all numbers on one line as shown.

//First test:

Enter positive integers (-1 to quit): 10 -5 2 -1 //User input

Entered Numbers: 10 2

The Sum: 12

Retry? (Y/N): Y //User input

//Second test:

Enter positive integers (-1 to quit): 1 2 3 4 5 6 -1

Entered Numbers: 1 2 3 4 5 6

The Sum: 21

Retry? (Y/N): Y

//Third test:

Enter positive integers (-1 to quit): 1 1 -7 1 1 -9 100 -1

Entered Numbers: 1 1 1 1 100

The Sum: 104

Retry? (Y/N): N

Program Terminated

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!