//判断一个五位数是否为回文数(万位与各位相等,千位与十位相等 如:12321) public static void main(String[] args){ System.out.println("请输入一个数:"); Scanner scanner = new Scanner(System.in); int ...
方法一:只限于五位数,而且笨
//判断一个五位数是否为回文数(万位与各位相等,千位与十位相等 如:12321)
public static void main(String[] args){
System.out.println("请输入一个数:");
Scanner scanner = new Scanner(System.in);
int num = scanner.nextInt();
int wan = num/10000;
int qian = num/1000 -wan*10;
int bai = num/100 - wan*100 - qian*10;
int shi = num/10 - wan*1000 - qian*100-bai*10;
int ge = num - wan*10000 - qian*1000 - bai*100 - shi*10;
if(wan == ge && qian == shi){
System.out.println("该数是回文数!");
}
else{
System.out.println("该数不是回文数!");
}
}
//double类型转换为int类型不需要强制转换如:
int a = 12321/10000;
a的值为1,不为1.2321
转为int型,把小数部位截断
int num = scanner.nextInt();后可以加上:
if(num >99999 || num