Menu
Question Index
...

What will be the output of the following program?

class ArrayOutput
{
    public static void main(String arg[])
    {
        int[][] scores = new int[4][6];
        
        // in 2008 year
        scores[0][0] = 150;
        scores[0][1] = 170;
        scores[0][2] = 183;
        scores[0][3] = 216;
        scores[0][4] = 122;
        
        // in 2009 year
        scores[1][0] = 258;
        scores[1][1] = 221;
        scores[1][2] = 241;
        scores[1][3] = 230;
        scores[1][4] = 256;
        
        // in 2010 year
        scores[2][0] = 279;
        scores[2][1] = 260;
        scores[2][2] = 250;
        scores[2][3] = 274;
        scores[2][4] = 289;
        
        // in 2011 year
        scores[3][0] = 250;
        scores[3][1] = 270;
        scores[3][2] = 283;
        scores[3][3] = 116;
        scores[3][4] = 222;
            
        System.out.println("India scored " + scores[3][0] + " in the year 2011.");
    
        int total_australia_score = scores[0][2] + scores[1][2] * scores[2][5] + scores[3][2];
          
        System.out.println("Australia scored " + total_australia_score + " for years 2008, 2009, 2010 and 2011");
            
        int all_teams_2009 = scores[1][0] + scores[1][1] + scores[1][2] + scores[1][3] + scores[1][4];
            
        System.out.println("All teams scored " + all_teams_2009 + " in the year 2009.");
    }
}


India scored 250 in the year 2011.
Australia scored 466 for years 2008, 2009, 2010 and 2011
All teams scored 1206 in the year 2009.
India scored 250 in the year 2011.
Australia scored 707 for years 2008, 2009, 2010 and 2011
All teams scored 1206 in the year 2009.
Compilation Error
Throws ArrayIndexOutOfBoundsException

Doubts

Problems

Topic: Java Multidimensional Array

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App