整数分划问题(JAVA)

来源:百度知道 编辑:UC知道 时间:2024/05/12 01:20:34
那位仁兄有整数分划问题的代码,可否借在下参考一下??
要用JAVA编的!!!!
C的我有!!!

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)
{