题目
样例
解题思路
1、 这是一个简单的题目,写这道题的目的是为了巩固charAt的方法,将数字转化成字符串,然后判断每个位置上的值。
2、 这道题需要注意的地方是,最后算和的时候需要减去Ascll的值48,这样得到的数值才是十进制的数值。
3、 下面直接给出代码。
参考代码
package DayDaytt;
import java.util.Scanner;
public class T112C {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
boolean b = false;
for (int i = 10000; i <= 99999; i++) {
String s = String.valueOf(i);
if (s.charAt(0) == s.charAt(4) && s.charAt(1) == s.charAt(3)
&& s.charAt(0) + s.charAt(1) + s.charAt(2) + s.charAt(3) + s.charAt(4) == n + 48 * 5) {
System.out.println(i);
b = true;
}
}
for (int i = 100000; i <= 999999; i++) {
String s = String.valueOf(i);
if (s.charAt(0) == s.charAt(5) && s.charAt(1) == s.charAt(4) && s.charAt(2) == s.charAt(3) && s.charAt(0)
+ s.charAt(1) + s.charAt(2) + s.charAt(3) + s.charAt(4) + s.charAt(5) == n + 48 * 6) {
System.out.println(i);
b = true;
}
}
if (b == false)
System.out.println(-1);
}
}