Menu
Topics Index
...
`

Fastest God


If you need explanation Read this topic

If you need Answer Take test on this topic

Fastest God
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);
        }
    }
}

A. GANESHKEYA
B. QA_XZPKEYA
C. QA
D. Some other output or Compilation Error or Runtime Error
Topic: Conclusion Of Strings 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.

ans c.
max =2.
for loop prints ly 2 chars
1st  'G'-'A' =6
6+'K'='Q'
nxt
'A'+'A'-'A'='A'

Posted by Maheshwari Natarajan    2014-07-11 13:30:04


ANS A : at char[0][] GANESH at char[1][]  KARTHIKEYA inside for loop if condition always results in FALSE as 2 not > 7 and 2not > 11 in 2nd for loop first conditional operator reults in true 0 < 7 gods[0][0] is G s'ly 2nd one ASCII value gets summed 71+75-65=81(Q) in 2nd iteration A(65)+ A(65)-A(65)=65(A) O/P is QA

Posted by BalRam At    2014-07-11 16:43:48


c

Posted by Arul Palanisamy    2014-07-12 04:16:49


Congratulations Maheshwari Natarajan. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-07-14 11:58:16


© meritcampus 2019

All Rights Reserved.

Open In App