palindrome of string Shraddha mams logic
import java.util.*;
class strings{
public static boolean palendrome(String str){
for(int i=0;i<str.length()/2;i++){
if(str.charAt(i)!=str.charAt(str.length()-i-1)){
return false;
}
}
return true;
}
public static void main(String[] args) {
String str="racpdcar";
boolean val=palendrome(str);
if(val==true){
System.out.println("String is palendrome");
}
else{
System.out.println("String is not a palendrome");
}
}
}
Comments
Post a Comment