Palindrome of string my logic
import java.util.*;
class strings{
public static void main(String[] args) {
String str="racpar";
String palendrome;
int count=0,i=0;
int start =0, end=str.length()-1;
while(i<end){
if(str.charAt(i)==str.charAt(end)){
count++;
end--;
i++;
}else{
break;
}
}
if(count==str.length()/2){
System.out.println("String is palendrome");
}
else{
System.out.println("String is not palendrome");
}
}
}
Comments
Post a Comment