代码有错,应该存在比1056大的数,所以改为2000吧,这个绝对够范围 新代码如下,当时没注意
package com.example.aaa;
public class Shu {
public static void main(String[] args) {
shu();
}
public static void shu(){
int[] a = new int[10];
for (int i = 0; i < a.length; i++) {
a[i] = 0;
}
for (int i = 0; i <= 9; i++) {
for (int j = 1023; j <= 2000; j++) {
for (int k = 10; k <= 98; k++) {
for (int l = 801; l <= 987; l++) {
if (i + k + l == j) {
int[] ba=shua(i, k, l, j);
boolean as = true;
for (int b = 0; b < 10; b++) {
if (ba[b] != 1) {
as = false;
break;
}
}
if(as==true){
System.out.println(i + " + "+ k + " + "+l+" = "+j );
}
}
}
}
}
}
}
public static int[] shua(int one,int two,int three,int four){
int[] a=new int[10];
for (int i = 0; i < a.length; i++) {
a[i]=0;
}
for (int i = 0; i < 4; i++) {
a[four%10]=1;
four=four/10;
}
for (int i = 0; i < 3; i++) {
a[three%10]=1;
three=three/10;
}
for (int i = 0; i < 2; i++) {
a[two%10]=1;
two=two/10;
}
a[one]=1;
return a;
}
}