Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design and implement a Java program that prompts the user to enter a series of p

ID: 3669318 • Letter: D

Question

Design and implement a Java program that prompts the user to enter a series of positive integer numbers. The program should accept integers until the user enters the value - 1 (negative one). 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. Entered Number: 10, 2, 13, 50, 100 The Sum: 175 Entered Number: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 The Sum: 55 Entered Number: 1, 1, 1, 1, 100 The Sum: 104 Entered Number: 0, 0, 0, 0, 0, 100 The Sum: 100 Make sure the program validates each entered number before processing it as the user may enter negative numbers other than the sentential value -1. Design your program such that it allows the user to re-run the program with a different set of inputs in the same run as shown above. Document your code, and organize and space out your outputs as shown above. My main question is how can i create this program without the comma showing up after the last input and print the out output of each input except for the sentinel value without using arrays. Thanks

Explanation / Answer

// Purpose: This program will prompt the user to enter a positive integer. // The program will accept integers until the user enters a -1. // Once the -1 is entered, the program will display the integers followed // by their sum. import java.util.Scanner; public class InputSum { public static void main(String[] args) { Scanner scan = new Scanner(System.in); // variable declaration int inputNumber; int stringNumber = 0; int num = 0; int sum = 0; // prompt user to enter an integer System.out.print("Enter a positive integer: "); inputNumber = scan.nextInt(); // continue to have user enter integers until: while (inputNumber >= 0) { sum += inputNumber; stringNumber+ = inputNumber++; System.out.print(" Enter another positive integer (enter -1 to quit): "); inputNumber = scan.nextInt(); // -1 is entered if (inputNumber == -1) { break; } } // display results System.out.print(" The integers you entered were: " + stringNumber); System.out.print(" The sum of the intergers are: " + sum); } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote