Menu
Question Index
...

What will be the output of the following program?

public class FastestGod {

    public static void main(String[] args) {
        char[][] gods = { "Ganesh".toUpperCase().toCharArray(), "Karthikeya".toUpperCase().toCharArray()};

        int max = 2, i = 0;
        for (i = 0; i < gods.length; i++) {
            if (max > gods[i].length) {
                max = gods[i].length;
            }
        }
        for (i = 0; i < max; i++) {
            char first = (i < gods[0].length) ? gods[0][i] : 'A';
            char second = (i < gods[1].length) ? gods[1][i] : 'A';
            char third = (char) (first + second - 'A');
            System.out.print(third);
        }
    }
}


GANESHKEYA
QA_XZPKEYA
QA
Some other output or Compilation Error or Runtime Error

Doubts

Problems

Topic: Conclusion Of Strings 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