Menu
Question Index
...

What will be the output of the following program?

public class TestWhile {

    public static void main(String[] args)
    {
        int i = 1;
        int j = 20;
        int k = 31;
        while (i < j) {
            k += (i * j);
            i = i * 2;
            j--;
        }
        System.out.println("i = " + i + " j = " + j + " k = " + k);
    }
}


i = 15 j = 13 k = 759
i = 16 j = 16 k = 297
i = 11 j = 10 k = 801
i = 15 j = 13 k = 808
Program goes into infinite loop

Doubts

Problems

Topic: while Loop In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App