Tuesday, September 22, 2009

Exercise 5

int product = 1;

for(int i = 2; i = num; i +=2){
product *= i;
}

Exercise 3

1. If statement needs brackets:

if (count == 5){
System.out.println("Sum = " + sum);
System.out.println("Product = " + product);
}//end of if statement

2. Do while loop needs semicolon:

do{

} while(count < 5);

3. The product variable initialization needs to equal 1 not 0 because 0 multiplied by 0 is 0:

int product = 1;