Menu
Question Index
...

What will be the output of the following program?

public class PrintPalindromes {
    public static void main(String s[]) {
        String input = "Malayalam";
        for (int i = 2; i < input.length(); i++) {
            for (int j = 0; j + i < input.length(); j++) {
                if (isPalindrome(input.substring(j, j + i + 1))) {
                    System.out.print(input.substring(j, j + i + 1) + "-");
                }
            }
        }
    }
    public static boolean isPalindrome(String input) {
        return input.equals(new StringBuffer(input).reverse().toString());
    }
}


M-a-l-a-y-a-l-a-ala-aya-ala-layal-alayala-
M-a-l-a-y-a-l-a-m-ala-aya-ala-layal-alayala-Malayalam-
ala-aya-ala-layal-alayala-Malayalam-
ala-aya-ala-layal-alayala-
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