Menu
Question Index
...

What will be the output of the following program?

public class NewQuestion
{
    public static void main(String[] args)
    {
        int j = 6, i = 0;
        System.out.print("Now i value and j value: ");
        for (int x = 1; i < ++x; i += x, j -= x)
        {
            System.out.print(i + " " + j + ", ");
        }
    }
}


Now i value and j value: 0 6, 1 5, 2 4, 3 3, 4 2,
Now i value and j value: 0 6, 2 4,
Now i value and j value: 0 6, 2 4, 4 2,
Program goes into infinite loop
Compilation Error or Runtime Error

Doubts

Problems

Topic: for 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