特殊回文数

题目如下:

思路:先把十进制数拆开,然后进行相关计算也行,但是,这里使用穷举法。

 1 import java.util.Scanner;
 2 class test 
 3 {
 4     public static void main(String[] args) 
 5     {
 6         int n;
 7         int i,j,k;
 8 
 9         Scanner scanner=new Scanner(System.in);
10         System.out.printf("输入n=");
11         n=scanner.nextInt();
12 
13         for(i=1;i<10;i++)//最高位必须不能为零,否则位数不正确
14         {
15            for(j=0;j<10;j++)
16            {
17               for(k=0;k<10;k++)
18               {
19                  if(2*i+2*j+k==n)
20                      System.out.printf("%7d",i*10000+j*1000+k*100+j*10+i);
21                  if(2*i+2*j+2*k==n)
22                      System.out.printf("%7d",i*100000+j*10000+k*1000+k*100+j*10+i);
23               }
24            }
25         }
26     }
27 }
原文地址:https://www.cnblogs.com/ttpn2981916/p/6420322.html