.
Previous Next

Write a Java Program to Check whether GivenString is palindrome or not

/*Q. Java Program to Check whether GivenString is palindrome or not  */
public class PolindromeString {
     public static void main(String[] args) {
           String str = "aba"; /* give input String here */
           String rev="";
           int length = str.length();
           for (int i = length - 1; i >= 0; i--) {      
                rev = rev + str.charAt(i);
           }
           if(rev.equals(str)){
                System.out.println("Given String is Polindrome");
           }
           else{
                System.out.println("Given String is not polindrome");
           }
     }

}
Previous Next