Menu
Topics Index
...
`

Print Palindromes2419


If you need explanation Read this topic

If you need Answer Take test on this topic

Print Palindromes2419
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());
    }
}

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 C...Each time the substring is checked for palindrome and that substring is printed

Posted by Badam Swathi    2014-07-15 09:38:03


Ans is C...Each time the substring is checked for palindrome and that substring is printed

Posted by Badam Swathi    2014-07-15 09:38:32


ans d.
methd prints palindrom substring of Malayalam in increasing ordr of string length

Posted by Maheshwari Natarajan    2014-07-15 09:39:51


Answer d
ispalindrome method check palindrom substring input.
for loop allows string length of greater thn 2.
it prints ala-aya-ala-layal-alayala- upto tis starting ltr M caps.so it nt prints malayalam

Posted by NagaRaj Nataraj    2014-07-15 09:48:14


d

Posted by Zeg Abder    2014-07-15 10:45:59


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

Posted by Merit Campus    2014-07-16 05:36:12


© meritcampus 2019

All Rights Reserved.

Open In App