You are on page 1of 1

import java.util.

*;
import java.io.*;
public class HelloWorld{

//code for smaller palins
//if the palin is odd it will check for the mid portion and //left and right are equal or not !
//if it is even it compares adjacent values and then checks for left and right are equal or not like
"##"
public static $tring shorterpalin%$tring s&int l&int r'
{
while%l()*++r,s.length%'++s.char-t%l'))s.char-t%r''
{
l..;
r//;
0
return s.substring%l/1&r';
0
public static $tring longpalin%$tring s'
{ $tring longest)s.substring%*&1';//assign smallest string to longest for checking
$tring palinstring;
//checking for the plaindromes in the given string and returns the longest
for%int i)*;i,s.length%'.1;i//'
{ //for odd palindromes
palinstring)shorterpalin%s&i&i';
if%palinstring.length%'(longest.length%''
longest)palinstring;
//for even palindromes
palinstring)shorterpalin%s&i&i/1';
if%palinstring.length%'(longest.length%''
longest)palinstring;
0
return longest;
0
public static void main%$tring 23args'{
$4stem.out.println%5enter the string 5';
$canner sin )new $canner%$4stem.in';
$tring input)sin.ne6t7ine%';
//8he longest plaindrome string
$tring longestpalin)longpalin%input';
$4stem.out.println%58he longest plaindrome string is 5/longestpalin';
0
0
sample input output9
enter the string :!;1<<<<1!<!
8he longest plaindrome string is 1<<<<1

You might also like