java练习题2
//题目一:一张纸的厚度大约是0.08mm,对折多少次之后能达到珠穆朗玛峰的高度(8848.13米)? int n=1; int a=8; while(a<=884813000) { a=a*2^n; n++; } System.out.println(n); //题目二:计算5的阶乘 5!的结果是? int b =1; int c=1; while(b<=5) { c=b*c; b++; } System.out.println(c); //计算 1+1/2!+1/3!+1/4!+...1/20!=? double d =1; double e=1; double f=0; while(d<=20) { e=(d*e); f=1/e+f; d++; System.out.println(f); }