标签:
import java.util.Scanner;
public class Main {
static char []str2 = new char [10];
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
boolean flag = false;
for (int i = 10000 ; i < 1000000 ; i++) {
String str1 = String.valueOf(i);
str2 = str1.toCharArray();
if(i < 100000 && str2[0] == str2[4] && str2[1] == str2[3])
{
int sum = (str2[0] - ‘0‘) + (str2[1] - ‘0‘) + (str2[2] - ‘0‘) + (str2[3] - ‘0‘) + (str2[4] - ‘0‘);
if(sum == n)
{
System.out.println(i);
flag=true;
}
}
else if(i >= 100000 && str2[0] == str2[5] && str2[1] == str2[4] && str2[2] == str2[3])
{
int sum = (str2[0] - ‘0‘) + (str2[1] - ‘0‘) + (str2[2] - ‘0‘) + (str2[3] - ‘0‘) + (str2[4] - ‘0‘) + (str2[5] - ‘0‘);
if(sum == n)
{
System.out.println(i);
flag=true;
}
}
}
if(flag==false)
System.out.println("-1");
}
}
标签:
原文地址:http://www.cnblogs.com/LuckyZcy/p/5182657.html