package com.java10.day03.section02; public class WhileTest { /** * 封装一个工具类计算一张1毫米的纸折叠多少次会超过10万公里 */ public static void whileTest(){ //1.设置一个次数变量 int count = 0; //2.设置while循环条件 double n = 1e-5; while (n <= 100000000) { n*=2; count+=1; } System.out.println("第" + count + "的厚度是" + n + "米" ); } public static void main(String[] args) { WhileTest.whileTest(); } }
#1.设置一个次数变量 count = 0 #2.设置while循环条件 n = 1e-5 while n <= 100000000: n *= 2 count += 1 print("第"+str(count)+"的厚度是"+str(n)+"米") print(count)