package com.itheima;
/*
纸张的厚度为0.001m,珠穆朗玛峰的高度为(8848.86m),请问要折叠多少次纸就可以保证纸张厚度不低于珠穆朗玛峰的高度?
*/
public class forDemo06 {
public static void main(String[] args) {
//定义统计变量,初始化值为0
int count = 0;
//定义珠穆朗玛峰高度和纸张厚度变量
double paper = 0.001;
double zf = 8848.86;
//用while循环实现反复折叠,判断纸张厚度是否小于珠穆朗玛峰高度
while (paper <= zf) {
//纸张折叠,厚度加倍
paper = paper * 2;
//统计折叠的次数
count++;
}
System.out.println("一共需要折叠" + count + "次");
}
}
原创文章,作者:,如若转载,请注明出处:https://blog.ytso.com/277602.html