Menu
Topics Index
...
`

Print Palindromes2418


If you need explanation Read this topic

If you need Answer Take test on this topic

Print Palindromes2418
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.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.

Answer is c .it prints all the palindromes that can be formed using the given word malayalam.All the palindromes should have min length of 3 and max length of 9 as the outer iteration specifies

Posted by Shashanka Mogaliraju    2014-08-14 12:44:18


ans d.prints polindroms of givn string length of increasing ordr.
length greater thn 2 n upto alayala.
Malayalam nt ptintd bcz starting m cap.
end m lwrcase

Posted by Maheshwari Natarajan    2014-08-14 13:11:30


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

Posted by Merit Campus    2014-08-15 06:05:23


© meritcampus 2019

All Rights Reserved.

Open In App