Question: Use do-while loop to Writes a program in java that reads and calculates the sum of an unspecified number of integers. The input 0 signifies

Use do-while loop to Writes a program in java that reads and calculates the sum of an unspecified number of integers. The input 0 signifies the end of the input.

Do you need to declare a new variable for each input value? No.

Just use one variable named data to store the input value and use a variable named sum to store the total.

Whenever a value is read, assign it to data and, if it is not zero, add it to sum

Sample input:

Enter an integer (the input ends if it is 0): 2

Enter an integer (the input ends if it is 0): 3

Enter an integer (the input ends if it is 0): 4

Enter an integer (the input ends if it is 0): 0

Sample output:

The sum is 9

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!