一个JAVA编程问题........

来源:百度知道 编辑:UC知道 时间:2024/06/20 00:40:01
四位整数1089,当它的数字逆向排列时是它自身的倍数(9801=9*1089).只有另外一个四位整数具有这个特性.编写一个程序,找出这个四位整数

如果上面的整数倍不包括1的话,那么答案是2178,程序如下

public class Test {
public static void main(String[] args) {
int a[]=new int[4];
int b;
for(int i=1000;i<10000;i++){
b=i;
for (int j=0;j<4;j++){
a[j]=b%10;
b=b/10;
}
int s=a[0]*1000+a[1]*100+a[2]*10+a[3];
for(int k=2;k<10;k++){
if (i*k==s){
System.out.println(i+" "+s);
}
}

}
}
}

//一共92个,自己运行看看是不是

public class NumberTest {

public static void main(String[] args) {
int from = 1000;
int to = 9999;
StringBuffer sb = null;
int count = 0;
for(int i = from ; i <= to; i ++) {
sb = new StringBuffer(i + "");
sb = sb.reverse();
if(Integer.parseInt(sb.toString()) % i == 0) {
count ++;
System.out.println(count + ": " + i);
}
}
}

}

public class Math {
pub