Question: Write a program (in Java) that prompts the user to input N integers, and output the sum of those N integers. You must write a
Write a program (in Java) that prompts the user to input N integers, and output the sum of those N integers. You must write a sentinal controlled while loop because user decides what N is.
import java.util.Scanner;
public class Lab5Part2{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int newNumber; //a number entered by the user
int count = 0; //used to count how many numbers are entered
int sum = 0; //accumulates the total of the numbers entered
final int sentinelValue = -1; //used as the stop value
// Write rest of the code here
System.out.println("The sum of your" + count + " numbers is: " + sum);
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
