Menu
Topics Index
...
`

Print team scores - Java Example Program


Print team scores
class PrintTeamScores
{
    public static void main(String arg[])
    {
        int[] scores = new int[4]; // LINE A - Creating the scores array.
        
        scores[0] = 200;    // assigning score for team 0 or India
        scores[1] = 190;    // assigning score for team 1 or Pakistan
        scores[2] = 210;    // assigning score for team 2 or Australia
        scores[3] = 195;    // assigning score for team 3 or Sri Lanka
        
        System.out.println("India = " + scores[0]);
        System.out.println("Pak = " + scores[1]);
        System.out.println("Aus = " + scores[2]);
        System.out.println("Sri Lanka = " + scores[3]);    
    }
}
OUTPUT

India = 200
Pak = 190
Aus = 210
Sri Lanka = 195

DESCRIPTION

This program creates an array of scores with size 4. The values (or elements) of the array are initialized using indices and later printed using indices.

THINGS TO TRY
  • Add 3 new teams England, Bangladesh and New Zealand. To do this increase the size of the array from 4 to 7 i.e. change LINE A to int[] scores = new int[7]; Also initialize the elements scores[4], scores[5] and scores[6] and print them.

© meritcampus 2019

All Rights Reserved.

Open In App