Menu
Question Index
...

What will be the output of the following program?

public class MahatmaGandhi {

    public static void main(String[] args) {
        String quotes[] = {"be", "change", "in", "must", "see", "the", "to", "wish", "world", "you"};
        int moves[] = {9, 4, -3, 5, 6, 8, -2, -1, -2, -2, 3, 3};
        int index = 0;
        for (int move : moves) {
            index += move;
            index %= quotes.length;
            System.out.print(quotes[index] + " ");
        }
    }
}


you must be the change you wish to see to you in
you must be the change wish to see in world
you must be the change you wish to see in the world
Some other output or 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