求1000-9999之间的回文数 回文数:若n=1221,则称n为一回文数;但若n=1234,则n不是回文数
Test.java
package Hcybx;
// 求1000-9999之间的回文数 回文数:若n=1221,则称n为一回文数;但若n=1234,则n不是回文数
public class Test {
public static void main(String[] args) {
int n = 1000;
int units = 0; //个位
int tens = 0; //十位
int hundreds = 0;//百位
int thousands = 0;//千位
while(n <= 9999) {
units = n % 10;
tens = n / 10 % 10;
hundreds = n / 100 % 10;
thousands = n / 1000 % 10;
if (units==thousands&&tens==hundreds) {
System.out.println("1000-9999的回文数有:"+n);
}
n++;
}
}
}