Menu
Question Index
...

What will be the output of the following program?

public class AnimalColors {
    public static void main(String[] args) {
        String[] animals = { "Crow", "Cow", "Parrot", "Pig"};
        String[] colors = { "Black", "White", "Green"};
        int map[] = { 1, 2, 3, 1};
        for (int i = 0; i < animals.length; i++) {
            System.out.println(animals[i] + " is " + colors[map[i]]);
        }
    }
}


Crow is Black
Cow is White
Parrot is Green
Pig is Black
Crow is White
Cow is White
Parrot is White
Pig is White
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java String Arrays - String Arrays 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