20175306 迭代和JDB调试

迭代和JDB调试

1.使用C(n,m)=C(n-1,m-1)+C(n-1,m)公式进行递归编程实现求组合数C(m,n)的功能

代码展示:

public class C {
public static void main(String args[]) {
int [] temp = new int [args.length];
int sum;
for(int i=0; i<args.length;i++) {
temp[i] = Integer.parseInt(args[i]);
}
sum = fact(temp[0],temp[1]);
if(sum == 0) System.out.println("error");
else System.out.println(sum);
}
public static int fact(int n , int m) {
if(m1) return n;
else if( m
0 || mn) return 1;
else if(n<m || n
0) return 0;
else
return fact(n-1, m-1)+fact(n-1,m);
}
}

2.提交测试运行截图(至少三张:正常如c(3,2)、异常如c(2, 3)、边界情况如c(m,m))

3.提交正常情况下用JDB调试程序c(X,2)的截图,X为学号最后一位+3,至少四张截图

JDB调试时遇到的问题:

  问题一:使用locals命令时显示本地变量信息不可用。
  解决过程:在编译时需要javac -g 命令以生成变量信息。
原文地址:https://www.cnblogs.com/wjs123456/p/10609801.html