问题描述
Java 代码实现
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
for (int i = 10000; i < 1000000; ++i) {
String s = String.valueOf(i);
StringBuilder reverse = new StringBuilder(s);// 记录反转后数字
if (s.equals(reverse.reverse().toString())) {
char[] ch = s.toCharArray();// 逆序取出数字
final int len = s.length();
int sum = 0;
for (int j = len-1; j >= 0; --j) {
sum += ch[j]-'0';
}
if (sum == n) {
System.out.println(s);
}
}
}
in.close();
}
}