String is palindrom or not
import java.util.Scanner; class StringPalindrom{ public static void main(String args[]){ Scanner sc = new Scanner(System.in); System.out.println("Enter a line"); String str = sc.nextLine(); String str1=""; char ch[] = str.toCharArray(); for(int i=ch.length-1;i>=0;i--) { str1+=ch[i]; } if(str.equals(str1)) System.out.println("Palindrom"); else System.out.println("Not palindrom"); } }
0 comments:
Post a Comment