Menu
Question Index
...

What will be the output of the following program?

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


India scored 279 in the year 2010.
Australia scored 674 in 3 years - 2008, 2009 and 2010.
All teams scored 950 in the year 2009.
India scored 230 in the year 2010.
Australia scored 674 in 3 years - 2008, 2009 and 2010.
All teams scored 950 in the year 2009.
India scored 279 in the year 2010.
Australia scored 900 in 3 years - 2008, 2009 and 2010.
All teams scored 950 in the year 2009.
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