Menu
Question Index
...

What will be the output of the following program?

class ForLoopOutput {
    public static void main(String[] args) {
        for (int i = 0; i < 8; i += 2) {
            method(i);
            System.out.print(i);
        }
    }

    private static void method(int i) {
        for (int j = 0; j < i; j++, i--) {
            System.out.print(" " + i + "~" + j + " ");
        }
    }
}


0 2~0  2~1 2 4~0  4~1  4~2  4~3 4 6~0  6~1  6~2  6~3  6~4  6~5 6
0 0~2 2 0~4  1~3 4 0~6  1~5  2~4 6
0 0~2 2 0~4  1~3 4 0~6  1~5  2~4 6 0~8  1~7  2~6  3~5 8
Some other output not shown here
Goes into infinite loop

Doubts

Problems

Topic: Java Methods - Parameter Passing And Scope

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App