Please check the following program and do let me know what is the problem with it. I'm not getting the desired output for it.
The program is to show that the string entered is palindrom or not. Initially I was trying to do it for a particular string and later on when the problem is resolved i'll take input from user. I know there are other methods to do it but what is wrong with it.
Code:class Palin { public static void main(String arg[]) { char a[]= new char[10]; char c[]={'a','d','a'}; String s1 = new String(c); int l; l=s1.length(); System.out.println("String is "+s1); for(int i=0,j=l-1; i<l;i++,j--) { a[i]=c[j]; } String s2 = new String(a); System.out.println("String after reversing is "+ s2); if(s1.equals(s2)==true) System.out.println("Its a Palindrom"); else System.out.println("Its not a Palindrom"); } }


Reply With Quote



Bookmarks