62,614
社区成员
发帖
与我相关
我的任务
分享
import java.io.*;
public class ExpermentFour_two
{
/**
* @param args
* Experment_Four_two
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
String str=new String("");
int i=0;
int len=0;
int flag=0;
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a number:");
do
{
try
{
str=in.readLine();
}
catch(IOException e)
{
System.out.print("ERROR!");
System.exit(0);
}
len=str.length();
for(i=0;i<len;i++)
{
if(str.charAt(i)<'0'||str.charAt(i)>'9'||str.charAt(0)=='0')
{
System.out.println("输入错误,重新输入!");
str=null;
flag=1;
break;
}
}
}while(flag==1);
for(i=0;i<len/2;i++)
{
if(str.charAt(i)!=str.charAt(len-i-1))
{
System.out.println("输入的数字是"+len+"位数 ,不是回文数! ");
return ;
}
}
System.out.println("输入的数字是"+len+"位数 ,是回文数! ");
}
}