-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalinLong.java
More file actions
33 lines (28 loc) · 833 Bytes
/
PalinLong.java
File metadata and controls
33 lines (28 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
public class PalinLong{
//longest palindrome in a string
public static void main(String []args){
String s = "forgeeksskeegfor";
String longest="";
for(int x=0;x<s.length();x++){
for(int y=x+1;y<=s.length();y++){
String t = s.substring(x,y);
if(isPalin(t)){
if(t.length()>longest.length()){
longest = t;
}
}
}
}
System.out.print(longest);
}
public static boolean isPalin(String s){
String rev="";
for(int x=s.length()-1;x>=0;x--){
rev = rev + s.charAt(x);
}
if(rev.equals(s))
return true;
else
return false;
}
}