Menu
Topics Index
...
`

Print Palindromes2420


If you need explanation Read this topic

If you need Answer Take test on this topic

Print Palindromes2420
What will be the output of the following program?
public class PrintPalindromes {
    public static void main(String s[]) {
        String input = "Malayalam";
        for (int i = 0; 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.

ans b
gvn strings substring of polindrm is printed in increasing ordr.

Posted by Maheshwari Natarajan    2014-09-08 12:47:16


answer a.
substrings of givn strngs polyndrom displayed in inc ordr.
upto alayala.
bcz m and M nt equl

Posted by NagaRaj Nataraj    2014-09-08 12:51:23


b.with each prnt stmnt all the palindrome combination substring of input are printed..frstly each lettr is passd thru fnctn n is printed since singl charachtr is palindrom to itself..

den all the palindrome substrngs r checked..n if found then printed

Posted by Asma Mujtaba Khan    2014-09-08 13:44:14


ans b : for each value of outer for loop its i value is taken as no.of letters to iterate and inner for loop goes throgh starting to final position of string based on no.of chars of i value...sub-string of positions is passed and compared in function if the string is palindrom it returns true or else false

Posted by BalRam At    2014-09-08 13:56:19


ans b.
palindrome substrins r printed in incr length of ordr .
equal ignore case usd fr chck.
so it just chck strings same or nt.
dnt chck capital r small word usd

Posted by Anand Kumar    2014-09-08 13:58:27


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-09-09 04:15:18


© meritcampus 2019

All Rights Reserved.

Open In App