Monday, 28 May 2012

Program in java to check a five digit number is a palindrome



import java.util.*;
class Palindrome
{
public static void main(String args[])
{
Scanner acn = new Scanner(System.in);
int ch=0;
while(true)
{
System.out.print("Enter A Five Digit Number : ");
int no=acn.nextInt();
String sno=String.valueOf(no);
if(sno.length()<5)
{
System.out.print("Length Is Less Than 5 Digit. Continue?(0)Yes/(1)No");
ch=acn.nextInt();
if(ch==1)
             break;
}
else
{
boolean flag=true;
int i=0;
int len=sno.length();
for(i=0;i<sno.length()/2;i++)
{
if(sno.charAt(i)!=sno.charAt(len-1))
flag=false;
len--;
}
if(flag)
System.out.println("Number Is Palindrome");
else
System.out.println("Number Is Not Palindrome");
System.out.print("Continue?(0)Yes/(1)No");
ch=acn.nextInt();
if(ch==1)
break;
}
}
}    }

1 comment:

  1. I have read your blog its very attractive and impressive. I like it your blog.

    Java Online Training Java EE Online Training Java EE Online Training Java 8 online training Core Java 8 online training

    Java Online Training from India Java Online Training from India Core Java Training Online Core Java Training Online Java Training InstitutesJava Training Institutes

    ReplyDelete