Java Reference
In-Depth Information
Syntax for while and do-while Statements
A while STATEMENT WITH A SINGLE-STATEMENT BODY
while ( Boolean_Expression )
Statement
A while STATEMENT WITH A MULTISTATEMENT BODY
while ( Boolean_Expression )
{
Statement_1
Statement_2
.
.
.
Statement_Last
}
A do-while STATEMENT WITH A SINGLE-STATEMENT BODY
do
Statement
while ( Boolean Expression );
A do-while STATEMENT WITH A MULTISTATEMENT BODY
Do not forget the
final semicolon.
do
{
Statement_1
Statement_2
.
.
.
Statement_Last
} while ( Boolean_Expression );
Give the user instructions.
count = 0;
sum = 0;
Read a number and store it in a variable named next.
while (next >= 0)
{
sum = sum + next;
count++;
Read a number and store it in next.
}
The average is sum/count provided count is not zero.
Output the results.
 
Search WWH ::




Custom Search