Sunday, July 10, 2011

Assignment 3 Excercise 3

/************************************
*T'Nora Green
*Assignment 3, Exercise 3
*************************************/
public class Numbers

{
public static void main (String[] args)
{
int count = 0;
int sum = 0;
int product = 1;
do
{
count++;
sum += count;
product *= count;
if (count == 5)
{
System.out.println("Sum = " + sum);
System.out.println("Product = " + product);
}
}
while (count < 5);

} //end main
} //end class Numbers

// solutions:
//must add a class heading
//change the placement of the opening and closing braces to inclose class and main method appropriately.
// change int product to 1
//add opening an closing braces around the if statement
//add semicolon to the end of the while statement

No comments:

Post a Comment