Menu
Topics Index
...
`

Dreams Memories Nothings


If you need explanation Read this topic

If you need Answer Take test on this topic

Dreams Memories Nothings
What will be the output of the following program?
public class DreamsMemoriesNothings {
    public static void main(String[] args) {
        String[] strings = {"Dreams", "Memories", "Nothings"};
        int count = 0;
        for (int i = 0; i < strings.length; i++) {
            String one = strings[i];
            for (int j = 0; j < strings.length; j++) {
                String two = strings[j];
                if (i == j) continue;
                for (int k = 0; k < one.length(); k++) {
                    for (int l = 0; l < two.length(); l++) {
                        if (isTrue(one, two, k, l)) {
                            count++;
                        }
                    }
                }
                System.out.print(count + "@");
            }
        }
    }
    private static boolean isTrue(String one, String two, int k, int l) {
        return Character.toUpperCase(one.charAt(k)) == Character.toUpperCase(two.charAt(l));
    }
}

A. 4@5@11@14@15@18@
B. 6@1@6@3@1@3@
C. 6@7@13@16@17@20@
D. Some other output or Compilation Error
Topic: Unknown

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.

Answer is C :: since count is 6 for "Dreams" and "Memories"then count is 7 for "Dreams" and "Nothings" now, count is 13 for "Memories" and "Dreams" as thn moving on, count is 16 for "Memories" and "Nothings" similaryl...17 and then 20 !! Thus C it should print.

Posted by Shaik Nyamath    2013-10-18 13:08:00


Congratulations Shaik Nyamath. You are this dose winner. We will send you the links using which you can claim your recharge.

Posted by Merit Campus    2013-10-20 12:03:51


© meritcampus 2019

All Rights Reserved.

Open In App