class WhileExample { public static void main(String s[]) { int n = 0;

int sum = 0;

while( n <= 6 ) { sum += n--; }

System.out.println("sum = " + sum); } }

sum = 21

sum = 28

Some other output

n = 0 n = 1 n = 2 n = 3 n = 4 n = 5 n = 6 sum = 21

Goes into infinite loop

Correct Answer : C

Execution of program starts from main. Inside main are two integer variables called n and sum are declared and are initialized to 0. The next statement is a while loop with condition n <= 6. As long as this condition is satisfied while loop is executed.
Initially n = 0. For every iteration value of n is decremented. So everytime n will be less than 6. Thus the n value will go till the end to the range and then return from positive value then it breaks the loop so we get output as sum = -1073741824.