public class Mytest
{
int total=0;
public void p2(int t1)
{
total=0;
System.out.println(t1);
total+=1;
p2(t1, "");
System.out.println("total:"+total);
System.out.println("-----------------");
}
private void p2(int t1, String t2)
{
for (int i = 1; i <= t1 / 2; i++)
{
if (t2.length() > 0)
{
if (i<Integer.parseInt(t2.charAt(1)+"")) continue;
System.out.println((t1 - i) + "+" + i + t2);
total+=1;
p2((t1 - i), "+" + i + t2);
}
else
{
System.out.println((t1 - i) + "+" + i);
total+=1;
p2((t1 - i), "+" + i);
}
}
}
public static void main(String[] args)
{
Mytest x = new Mytest();
x.p2(7);
}
}
//解决了别忘了给分呀
温馨提示:答案为网友推荐,仅供参考