Menu
Question Index
...

What will be the output of the following program?

class PrintName
{
    public static void main(String[] args)
    {
        char chars[] = {'a', 'd', 'e', 'i', 'k', 'n', 'V', 'v'};
        char moves[] = {6, 5, 4, 3, 10, 4, 5, 3, 5, 3, 1, 7};
        int j = 0;
        for (char move : moves)
        {
            j += move;
            j %= chars.length;
            System.out.print(chars[j]);
        }
    }
}


ananda
Viveka
Vivekananada
Throws ArrayIndexOutOfBoundsException

Doubts

Problems

Topic: For-each Loop In Core Java Programming

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App