黑马程序员技术交流社区
标题:
折纸多少次能达到珠峰高度?
[打印本页]
作者:
a554305211
时间:
2015-8-24 21:17
标题:
折纸多少次能达到珠峰高度?
纸张折叠成珠穆朗玛峰高度的次数
class TestZhuFeng {
/*
珠峰:8488
纸张厚度:0.01m
问:纸张对折多少次能达到珠峰高度?
*/
public static void main(String[] args) {
int count = getCount(0.01);
System.out.println("对折次数:" + count);
}
public static int getCount(double height){
int count = 0;
while (height <= 8488.0) {
height *= 2;
count++;
}
return count;
}
}
复制代码
作者:
氕氘氚
时间:
2015-8-24 21:28
能用int类型还是用int类型,不要用double类型
作者:
cemabenteng
时间:
2015-8-24 21:37
20次,这应该是基础六七天的内容吧
作者:
jeska
时间:
2015-8-24 21:42
public static void zhuFeng(){//上珠峰折纸
int count=0;
double x=0.01;//一张纸1cm厚
while(x<=8848.1){
x*=2;
count+=1;
}
System.out.println("一张纸对折到珠峰的高度需要折纸的次数为:"+count);
给你助助兴
作者:
Five_伍
时间:
2015-8-24 21:59
灰常好,。赞个
作者:
ruili
时间:
2015-8-24 22:22
今天刚写完,
作者:
收获远眺
时间:
2015-8-24 22:35
赞一个........
作者:
Marx_D
时间:
2015-8-25 00:08
在java中一切的浮点运算都是不准确的,所以
作者:
a554305211
时间:
2015-8-25 18:06
氕氘氚 发表于 2015-8-24 21:28
能用int类型还是用int类型,不要用double类型
嗯好的谢谢
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2