黑马程序员技术交流社区
标题:
解决下这个问题
[打印本页]
作者:
佐佑
时间:
2015-3-26 23:30
标题:
解决下这个问题
一张足够大的纸,厚度0.01米,珠穆拉玛8848米,需要进行多少次
用代码实现
作者:
Grady
时间:
2015-3-26 23:44
用while循环
作者:
大神在何方
时间:
2015-3-26 23:45
我自己也不会啊。。。我也给这个难住了·学习能力差
作者:
Dark县令
时间:
2015-3-26 23:46
用for if 嵌套,并且通过计数器count来累加次数!用x+=0.01;和count++;来实现。
作者:
有丶时候
时间:
2015-3-27 11:45
额,需要进行多少次什么? 折叠么?
作者:
hellotaomi
时间:
2015-3-27 12:14
class Demo
{
public static void main(String[] args)
{
int count=0;
double y=8848;
double x=0.01;
while(x<8848)
{
x=x*2;
count++;
}
System.out.println(count);
}
}
上面是我写的代码,
运算出的结果为20次。一开始我很惊讶,可是好像结果就是这么不可思议~
作者:
零点Crazy
时间:
2015-3-27 12:57
/*
一张足够大的纸,厚度0.01米,珠穆拉玛8848米,需要进行多少次
用代码实现
*/
class Test
{
public static void main(String[] args)
{
int count=0;
double height=0.01;
while (height<8848)
{
height=height*2;
count++;
}
System.out.println(count);
for (double x=0.01;x<8848 ;x*=2 )
{
count++;
}
System.out.println(count);
do
{
height=height*2;
count++;
}
while (height<8848)
System.out.println(count);
}
}
最后的结果和楼上一致,20次。三种循环方式都写了一遍,希望对你有帮助。
作者:
田晓莉
时间:
2015-3-27 13:02
额!还真的是20次,好意外的说
class luntan_0327
{
public static void main(String[] args)
{
int count = 0;
double x = 0.01;
while(x<8848)
{
x = x*2;
count ++;
}
System.out.println("折叠次数:"+count);
}
}
复制代码
作者:
lffwsjj
时间:
2015-3-27 14:59
进行多少次什么啊
作者:
刚起步的小马驹
时间:
2015-3-27 18:26
结果确实有点意外,有高手:
作者:
longlongint
时间:
2015-3-27 18:40
就是计算2的阶乘,用递归就可以了
作者:
Catface
时间:
2015-3-27 19:37
一个for循环
作者:
l540144279
时间:
2015-3-27 21:06
代码就是楼上的了,据科学证明,一张实在存在的纸无法对折9次! 最多八次!不信可以试试
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2