Caballarii
static int argument;
static int count=0;
public static void main(String[] args){
argument=5;
printResult("",argument);
System.out.println("总共"+count+"种");
}
public static void printResult(String result,int left){
if(left==1){
System.out.print(argument+"=");
for(int i=0;i
System.out.print(result.charAt(i)+"+");
}
System.out.print(1);
System.out.println();
count++;
}
else if(left==2){
System.out.print(argument+"=");
for(int i=0;i
System.out.print(result.charAt(i)+"+");
}
System.out.print(2);
System.out.println();
count++;
printResult(result+"1",left-1);
}
else{
printResult(result+"1",left-1);
printResult(result+"2",left-2);
}
}不光把铺法数量输出了,还把具体的铺法输出了