pTutorial

New way to learn Programming

Check for palindrome String

palindrome String example


import java.util.Scanner;

class CheckPalindrome{
    
static String k;

static boolean palindrom(String temp){

    k=temp;

    int j=0;
    
    int flag=0;
    
    char ch[] =k.toCharArray();
    
    char[] ch1=new char[ch.length];

    for(int i=ch.length-1;i>=0;i--,j++){
        
        ch1[j]=ch[i];
}
    
for(int i=0;i<=ch.length-1;i++){
    
    if(ch[i]==ch1[i]){
        flag=1;
    }
    else{
        flag=0;
        break;        
    }
      
}

if(flag==1) 
    System.out.println(k+"\t"+"string is palindrom");
else
    System.out.println(k+"\t"+"string is not palindrom");
return true;

}

public static void main(String...s){

    Scanner input = new Scanner(System.in);
        
    System.out.println("Enter a string"); 
        
    String str=input.nextLine();
        
    palindrom(str);
}

}

Output

Enter a string
uKu
uKu	string is palindrom

See Also


QUOTES OF THE DAY

Knowledge without integrity is dangerous and dreadful.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER