时间:2021-07-01 10:21:17 帮助过:18人阅读
public class Combination {
public static void main(String args[]) {
int c,n,m;
n = Integer.parseInt(args[0]);
m = Integer.parseInt(args[1]);
c = Result(n, m);
if (c == -1) System.out.println("Input error: m cannot be larger than n !");
else if (c == -2)System.out.println("Input error: m and n cannot be less than zero !");
else System.out.println(c);
}
public static int Result(int n, int m) {
if (m == 1) return n;
else if (m == 0 || m == n) return 1;
else if (n < m && n>0 && m>0) return -1;
else if (n < 0 || m < 0) return -2;
else
return Result(n - 1, m - 1) + Result(n - 1, m);
}
}
- 异常情况
- 边界情况
正常情况下用JDB调试程序c(X,2),X为学号最后一位+3
我学号5214,即取c(7,2)调试。调试情况截图
迭代和JDB
标签:合数 put string 调试 ror cannot less 测试 mamicode