Menu
Question Index
...

Compare the following programs?

class ArrayOutput1
{
    public static void main(String s[])
    {
        int marks[] = new int[4];
        marks = new int[] {87, 76, 84, 57};
        
        for(int i = 0; i < 4; i++)
        {
            System.out.println(marks[i]);
        }
    
    }
}

class ArrayOutput2
{
    public static void main(String s[])
    {
        int marks[] = new int[4];
        marks = new int[{87, 76, 84, 57}];
        
        for(int i = 0; i < 4; i++)
        {
            System.out.println(marks[i]);
        }
    
    }
}


Both ArrayOutput1 and ArrayOutput2 produce same output
ArrayOutput2 does not compile, but ArrayOutput1 will compile
ArrayOutput1 does not compile, but ArrayOutput2 will compile
Both ArrayOutput1 and ArrayOutput2 compile, but they produce different output

Doubts

Problems

Topic: Learn Arrays And Loops

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App