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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started