Menu
Question Index
...

Compare the following Programs?

public class LoopExample1
{
    public static void main(String[] args)
    {
        for (char i = 0, j = 1; i < 5 && j < 6; i++)
        {
            System.out.print((int) i + " " + (int) j + ", ");
            j++;
        }
    }
}

public class LoopExample2
{
    public static void main(String[] args)
    {
        for (int i = 0, j = 1; i < 5 && j < 6; i++)
        {
            System.out.print(i + " " + j + ", ");
            j++;
        }
    }
}


Both LoopExample1 and LoopExample2 produce same output.  
LoopExample1 and LoopExample2 produce different output.
LoopExample2 compiles and runs with out any error,
but LoopExample1 gives compilation error.
LoopExample1 compiles and runs with out any error,
but LoopExample2 gives compilation error.
Both LoopExample1 and LoopExample2 fail to execute.

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