Menu
Topics Index
...
`

Print Characters From Array1222


If you need explanation Read this topic

If you need Answer Take test on this topic

Print Characters From Array1222
What will be the output of the following program?
public class XYZ {

    public static void main(String args[]) {
        char array[] = {'a', 'b', 'c', 'd'};
        for (char element : array) {
            for (char result : array) {
                System.out.print(element + "~" + result);
            }
        }
    }
}

A. a~ab~ac~ad~aa~bb~bc~bd~ba~cb~cc~cd~ca~db~dc~dd~d
B. a~aa~ba~ca~db~ab~bb~cb~dc~ac~bc~cc~dd~ad~bd~cd~d
C. a~ab~bc~cd~da~ab~bc~cd~da~ab~bc~cd~da~ab~bc~cd~d
D. aa~ab~ac~ad~ba~bb~bc~bd~ca~cb~cc~cd~da~db~dc~dd~
E. Compilation Error or Runtime Error
Topic: For-each Loop In Core Java Programming

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.

option b is the answer because result is in inner loop

Posted by Sai Lalitha Renduchintala    2013-04-22 12:47:54


option b is the answer since the inner loop values are tagged with current val in outer loop

Posted by Karteek Paruchuri    2013-04-22 12:51:58


option b is the answer as each element is linked to every other element using the two for loops and each time we get a combination aa ab ac ad ba bb bc bd .........

Posted by Vinay Reddy    2013-04-22 13:49:11


Congratulations Sai Lalitha. You are today's daily dose winner. Can you please send us your mobile details and we will process the recharge tomorrow after considering the new likes.

Posted by Merit Campus    2013-04-22 16:13:15


ThankQ MC .. Received RC .. :)

Posted by Sai Lalitha Renduchintala    2013-04-24 13:01:26


© meritcampus 2019

All Rights Reserved.

Open In App