抱歉,自己大意了,把temp的赋值表达式定义错了,一直无限循环paper*2
public class Demo5 {
public static void main(String[] args) {
//定义山高的变量height
double height = 8848.0;
//定义纸张厚度变量paper
double paper = 0.01;
//临时变量temp
double temp;
//定义计数变量count
int count = 0;
for (temp=paper;temp<height;count++)
temp = temp*2;
System.out.println("总共折了"+count+"次!");
}
} |