Menu
Question Index
...

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


4@5@11@14@15@18@
6@1@6@3@1@3@
6@7@13@16@17@20@
Some other output or Compilation Error

Doubts

Problems

Topic: Unknown

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App