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

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!