description:
从m位的十进制数中找出各个位数之和等于n的回文数
//回文数
package day07;
import java.util.Scanner;
public class day09 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int m = scan.nextInt();
int temp1 = 1;
int temp2 = 1;
int []a = new int [10];
for(int i = 1;i<n;i++){
temp1 *= 10;
}
for(int i = 1;i<n+1;i++){
temp2 *= 10;
}
temp2 -=1;
for(int i = temp1;i<temp2;i++){
boolean flag = true;
int sum = 0;
a=getBack(i,n);
for(int j = 0;j<n/2;j++){
if(a[j]!=a[n-j]){
flag = false;
}
}
for(int j = 0;j<n;j++){
sum += a[j];
}
if(flag && sum==m){
System.out.println(i);
}
}
}
public static int[] getBack(int num,int count){
int []a = new int [10];
for(int i = 0;i<count;i++){
a[i] = num%10;
num /=10;
}
return a;
}
}
|