3 回答
Caballarii
TA贡献1123条经验 获得超629个赞
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<result.length();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<result.length();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); } }
不光把铺法数量输出了,还把具体的铺法输出了
添加回答
举报
0/150
提交
取消