zoukankan      html  css  js  c++  java
  • [蓝桥] 基础练习 回文数

    问题描述

    1221是一个非常特殊的数,它从左边读和从右边读是一样的,编程求所有这样的四位十进制数。

    输出格式

    按从小到大的顺序输出满足条件的四位十进制数。

     

    刚开始没注意到10001,从1111开始的,写了两段代码,其实都一样.

     1 public class Main {
     2     public static void main(String[] args) {
     3         for(int i = 1001;i <= 9999;i++) {
     4             int left = i / 100;
     5             int right = i % 100;
     6             right = (right % 10) * 10 + right / 10;
     7             if(left == right)
     8                 System.out.println(i);
     9         }
    10     }
    11 
     1 public class Main {
     2     public static void main(String[] args) {
     3         for(int i = 1001;i <= 9999;i++) {
     4             int s = i;
     5             int[] arr = new int[4];
     6             int t = 0;
     7             while(s != 0) {
     8                 arr[t++] = s % 10;
     9                 s /= 10;
    10             }
    11             if(arr[0] == arr[3] && arr[1] == arr[2]) {
    12                 for(int j = 0;j < 4;j++) {
    13                     System.out.print(arr[j]);
    14                 }
    15                 System.out.println();
    16             }
    17         }
    18     }
    19 }
  • 相关阅读:
    Mysql任务调度
    使用 IntraWeb (18)
    使用 IntraWeb (17)
    替盛大代发的招聘启示
    使用 IntraWeb (16)
    使用 IntraWeb (15)
    使用 IntraWeb (14)
    使用 IntraWeb (13)
    使用 IntraWeb (12)
    使用 IntraWeb (11)
  • 原文地址:https://www.cnblogs.com/youpeng/p/10349066.html
Copyright © 2011-2022 走看看