假設某個四位數滿足abcd*e=dcba,a不等於0,e非0非1,找出滿足條件的abcd和e
number is 2178 e is 4
/**
* @param args
* 假設某個四位數滿足abcd*e=dcba,a不等於0,e非0非1,找出滿足條件的abcd和e
*/
public static void main(String[] args) {
//e>1,所以 abcd一定是在4999以內
for(int e=2;e<9;e++)
{
for (int i = 1001; i < 4999; i++) {
int resultNumb=i*e;
if(resultNumb>9999)
{
break;
}
if(resultNumb==getReNumber(i))
{
System.out.println("number is "+i+" e is " +e);
}
}
}
}
//假設某個四位數滿足abcd*e=dcba,a不等於0,e非0非1,找出滿足條件的abcd和e
private static int getReNumber(int num)
{
//由於num一定是四位數,所以轉換後
int d=num%10;
int c=num/10%10;
int b=num/100%10;
int a=num/1000;
int result= d*1000+c*100+b*10+a;
return result;
}