TA的每日心情 | 开心 2021-3-12 23:18 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
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[i] != 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
- ",i);
- System.out.printf("The velocity of the car is:%.2f
- ",(i-95859)/2.0);
- break;
- }
- }
- }
- }
- 运行:
- C:at>java Test22
- The new symmetrical number kelometers is:95959
- The velocity of the car is:50.00
复制代码
源码下载:http://file.javaxxz.com/2014/11/28/000557421.zip |
|