标签:
一张纸的厚度0.08mm,假设可以无限次对折,求对折多少次之后 会超过珠穆朗玛峰的高度8848.13m
1 double num1=0.08; 2 int i=1; 3 while(num1/1000<=8848.13) 4 { 5 num1*=2; 6 System.out.println("第"+i+"次对折的厚度:"+num1/1000+"米"); 7 i++; 8 9 } 10 System.out.println("一共对折"+i+"次!");
结果:
求5的阶乘:
1 int jx=1; 2 for(int j=1;j<=5;j++){ 3 jx*=j; 4 } 5 System.out.println("5!="+jx);
计算 1+1/2!+1/3!+1/4!+...1/20!=?
double res=0; for(int k=1;k<=20;k++){ double jc=1; for(int m=1;m<=k;m++){ jc*=m; } res+=1/jc; System.out.println(k+"!="+jc); System.out.println(res); } System.out.println("1+1/2!+1/3!+1/4!+...1/20!="+res);
结果:
标签:
原文地址:http://www.cnblogs.com/ouyangtangfeng99/p/5473662.html