Menu
Topics Index
...
`

Print Palindromes2421


If you need explanation Read this topic

If you need Answer Take test on this topic

Print Palindromes2421
What will be the output of the following program?
public class PrintPalindromes {
    public static void main(String s[]) {
        String input = "Malayalam";
        for (int i = 1; i < input.length(); i++) {
            for (int j = 0; j + i < input.length(); j++) {
                if (isPalindrome(input.substring(j, j + i))) {
                    System.out.print(input.substring(j, j + i) + "-");
                }
            }
        }
    }
    public static boolean isPalindrome(String input) {
        return input.equalsIgnoreCase(new StringBuffer(input).reverse().toString());
    }
}

A. M-a-l-a-y-a-l-a-ala-aya-ala-layal-alayala-
B. M-a-l-a-y-a-l-a-m-ala-aya-ala-layal-alayala-Malayalam-
C. ala-aya-ala-layal-alayala-Malayalam-
D. ala-aya-ala-layal-alayala-
E. 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 is : A, because every palindrome of sub-string of a given input is printed.

Posted by Mallikarjuna Rao    2014-02-07 08:44:26


Ans is d because every palindrome of sub string is printed and input must be in strings

Posted by Lavanya Kategaru    2014-02-07 12:27:53


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

Posted by Merit Campus    2014-02-10 04:01:03


© meritcampus 2019

All Rights Reserved.

Open In App