Tuesday, February 18, 2014

IT-415 Assignment 3

Problem 3

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
public class HelloWorld{

     public static void main(String []args){
        int count = 0;
        int sum = 0;
        int product = 1; // Needed to be 1
        do
        {
            count++;
            sum+= count;
            product *= count;
            if (count == 5) {  // Brackets were needed for if statement
                System.out.println("Sum = " + sum);
                System.out.println("Product = " + product);
            }
        } while (count < 5); // Needed semicolon
     }
}

Problem 5

line# i debug output
3 ?
4 ?
5 0
10 first
5 1
13 second
5 2
17 In default
5 3
20 i = 3

No comments:

Post a Comment