//please save this code as Palindrome.java or download the given file and compile it with " javac Palindrome.java " //After successful compilation run this with " java Palindrome" at CMD // Make sure you have java already //installed in your system CODE : : import java.util.*; class Palindrome { public static void main(String m[]) { Scanner in=new Scanner(System.in); String s=new String(); boolean f=false; System.out.println("Enter String to check it's palindrome or not::"); s=in.next(); int l=s.length()-1; for(int i=0;i<l;i++,l--) { if(s.charAt(i)==s.charAt(l)) { f=true; } else { f=false; } } if(f) { System.out.println("String is palindrome"); } else { System.out.println("String is not palindrome"); } } } OUTPUT : :
Your comment will be posted after it is approved.
Leave a Reply. |
Hello friends, i am a CSE student and i am going to upload all the programs of various language which might be in your collage practical list or might help you in performing your practicals in lab. Archives
August 2015
Categories |