不怎么明白你的意思。 public class test { public static void main(String[] args) { for(int a = 9;a> -1;a--) { for(int b = 9;b > -1;b--) { for(int c = 9;c>-1;c--) { if((a + b + c) == 10) { System.out.println(10000*a + b*1000 + c* 100 + 99); } } } } } }
弄了个比较烂的写法: int a,b,c,d,e; for(int i =10000;i<99999;i++) { a = i/10000; b = i%10000/1000; c = i%1000/100; d = i%100/10; e = i%10; if((a+b+c+d+e)==19 || (a+b+c+d+e)==29) { System.out.println("这个5位数是:"+a+b+c+d+e); } else continue;
public class TestNumber { public static void main(String[] args) { int i = 0; int count = 0; for(i=10000; i<100000; i++) { String str = String.valueOf(i); int num1 = Integer.parseInt("" + str.charAt(0)) + Integer.parseInt("" + str.charAt(1)) + Integer.parseInt("" + str.charAt(2)); int num2 = Integer.parseInt("" + str.charAt(3)) + Integer.parseInt("" + str.charAt(4)); if(((num1==10) || (num1==20)) && (num2==9)) { count++; if(count%10==0) System.out.println(); System.out.print(i + " "); }else continue; } } } 楼主的意思看不明白 是这样的吗? 前三位数之和为10或20,后两位数值和为9
public class test {
public static void main(String[] args) {
for(int a = 9;a> -1;a--) {
for(int b = 9;b > -1;b--) {
for(int c = 9;c>-1;c--) {
if((a + b + c) == 10) {
System.out.println(10000*a + b*1000 + c* 100 + 99);
}
}
}
}
}
}
for(int i =10000;i<99999;i++)
{
a = i/10000;
b = i%10000/1000;
c = i%1000/100;
d = i%100/10;
e = i%10;
if((a+b+c+d+e)==19 || (a+b+c+d+e)==29)
{
System.out.println("这个5位数是:"+a+b+c+d+e);
}
else
continue;
public class TestNumber {
public static void main(String[] args) {
int i = 0;
int count = 0;
for(i=10000; i<100000; i++) {
String str = String.valueOf(i);
int num1 = Integer.parseInt("" + str.charAt(0)) +
Integer.parseInt("" + str.charAt(1)) +
Integer.parseInt("" + str.charAt(2));
int num2 = Integer.parseInt("" + str.charAt(3)) +
Integer.parseInt("" + str.charAt(4));
if(((num1==10) || (num1==20)) && (num2==9)) {
count++;
if(count%10==0)
System.out.println();
System.out.print(i + " ");
}else
continue;
} }
}
楼主的意思看不明白
是这样的吗? 前三位数之和为10或20,后两位数值和为9
假设五位数分别为:x1x2x3x4x5
且五位数中,假设满足这样的条件:
情况一:x1+x2+x3=10或者20,余下的两位相加即为x4+x5
情况二:x1+x3+x5也等于10或者20,余下的两位相加即为x2+x4
如果有x4+x5 > x2+x4
那么“情况一”就是我们所要找的!因为它除了满足三个数之和为10或者20外,且满足余下的两位数之和为“相对”最大值!