Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Use while loop to Write 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database Design A Practical Approach

Authors: Marilyn Campbell

1st Edition

1587193175, 978-1587193170

More Books

Students also viewed these Databases questions

Question

6. Conclusion:

Answered: 1 week ago