Menu
Topics Index
...
`

Mahatma Gandhi


If you need explanation Read this topic

If you need Answer Take test on this topic

Mahatma Gandhi
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] + " ");
        }
    }
}

A. you must be the change you wish to see to you in 
B. you must be the change wish to see in world 
C. you must be the change you wish to see in the world 
D. Some other output or Compilation Error or Runtime Error
Topic: Java String Arrays - String Arrays In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

anc is 'd'  it gives runtime error..

Posted by Sadanand Kalyankar Patil    2013-10-02 04:09:19


Answer is C,
There will be no errors,
first the index 9 will be printed and then 9+4=13%10=3 so index 3 will be printed 3-3=0 0 index will be printed so on...
The output will be 'you must be the change you wish to see in the world.

Posted by Amar Kumar Biradar    2013-10-02 04:17:20


Congratulations Amar Kumar Biradar. You are this dose winner. We will send you the link using which you claim your recharge.

Posted by Merit Campus    2013-10-03 10:24:03


Thanks Merit campus :)
Got Recharge =D ;)

Posted by Amar Kumar Biradar    2013-10-03 10:38:25


© meritcampus 2019

All Rights Reserved.

Open In App