计算阶乘
public class homework { public static void main(String[] args) { // 用循环实现阶乘 int n = 4; //4! = 1*2*3*4=24 long l = 1;//阶乘计算结果 for(int i = 1;i<=n;i++){ l = l*i; System.out.println("l="+l); } System.out.println(n+ "!="+l);
double t =0; long u =1;{ for(int i =1;i<=20;i++){ u=u*i; t =t+1/(double)u; } System.out.println("测试"+"!="+t) ; }