|
C语言趣味程序百例精解之java实现(22)求车速
程序:
public class Test22{
public static void main(String args[]){
symmetricNumber();
}
/**
*是回文数
*/
/** 检验数字是否是回文的 */
public static boolean isPalindrome(long num) {
long[] digits = new long[19];
if (num >= 0 && num <= 9)
return true;
int nDigits = 0;
while (num > 0) {
digits[nDigits++] = num % 10;
num /= 10;
}
for (int i=0; i< nDigits/2; i++)
if (digits != digits[nDigits - i - 1])
return false;
return true;
}
/**
* 22.对称数
*/
public static void symmetricNumber() {
int a[]=new int[5];//数组a存放分解的数字位
for(int i=95860;i<100000;i++){
if(isPalindrome(i)){
System.out.printf("The new symmetrical number kelometers is:%d\n",i);
System.out.printf("The velocity of the car is:%.2f\n",(i-95859)/2.0);
break;
}
}
}
}
运行:
C:\bat>java Test22
The new symmetrical number kelometers is:95959
The velocity of the car is:50.00 |
|