wuhao0727 闲着无聊,用java写了个,楼主有jre运行环境知道怎么运行,就运行看结果吧,输入2,3,4,5,6,8 然后按回车看结果。
import java.io.*;
public class Choose {
int init[];
int end[];
int n;
int m;
BufferedReader in;
int tempint=0;
public Choose() {
in=new BufferedReader(new InputStreamReader(System.in));
getInput("Please enter number string like 2,3,5,7 : ");
m=2;
end=new int[m];
choose1(0,0);
m=3;
end=new int[m];
choose1(0,0);
m=4;
end=new int[m];
choose1(0,0);
}
public static void main(String arf[]) {
Choose demo=new Choose();
}
public void choose1(int k,int l) {
tempint=0;
if(l==m) {
for(int i=0;i<m;i++){
//System.out.print(end+" ");
tempint=tempint+end;
}
if(tempint % 10 ==0) {
for(int i=0;i<m;i++){
if(i==m-1){
System.out.print(end+"=");
}else {
System.out.print(end+"+");
}
}
System.out.print(tempint);
System.out.println();
}
}
else if(n-k==m-l) {
for(int i=0;i<m-l;i++){
end[l+i]=init[k+i];
}
for(int i=0;i<m;i++){
//System.out.print(end+" ");
tempint=tempint+end;
}
if(tempint % 10 ==0) {
for(int i=0;i<m;i++){
if(i==m-1){
System.out.print(end+"=");
}else {
System.out.print(end+"+");
}
}
System.out.print(tempint);
System.out.println();
}
}
else {
end[l]=init[k];
choose1(k+1,l+1);
choose1(k+1,l);
}
}
public void getInput(String info) {
String[] temp;
System.out.print("\n"+info);
try {
temp=in.readLine().split(",");
n = temp.length;
if(n<4) {
System.out.println("\nWrong!! enter at least 4 numbers like 2,3,5,6 !");
getInput("Enter again : ");
}
init=new int[n];
for(int i=0;i<n;i++) {
init=Integer.parseInt(temp);
}
}
catch(Exception e) {
System.out.println("Wrong!! Input again!!");
getInput(info);
}
}
}