Menu
Question Index
...

What will be the output of the following program?

class MultiVariableFor
{

    public static void main(String s[])
    {
        int a, b;
        for(a = 1, b = 4; a < b; a++, b--)
        {
            System.out.println("a = " + a);
            System.out.println("b = " + b);
        }
    }
}


Compilation error since both a++ and b--
should not be present in the iteration section (i.e after the second semicolon)
a = 1
b = 4
a = 2
b = 3
a = 3
b = 2
a = 1
b = 4
a = 2
b = 3
Compilation error since both a = 1 and b = 4
should not be present in the initialization section (i.e before the first semicolon)

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