闲来无聊,知道为什么一张纸只能对折8次吗?
哈哈,看看程序:
public class TestCount {
static Integer count = 0; //对折次数
public static void main(String[] args) {
Double maxHight=0.0; //最大宽度,别介意单词· - ·
Double minHight=0.0; //最小宽度
Double land = 0.1; //纸张厚度
Double hight = 297.0; //A4纸长度
Double width = 210.0; //A4纸宽度
if (hight>width){ //把最长的边给maxHight,最短的边给minHight
maxHight = hight;
minHight = width;
}else {
maxHight = width;
minHight = width;
}
made(maxHight, land,minHight); //对折了,看好了
System.out.println(count);
}
private static void made(Double maxHight, Double land,Double minHight) {
if (land<maxHight){ //厚度和最宽的地方比较
land = land*2; //对折,厚度翻倍
maxHight = maxHight/2; //最大宽度对半
Double temp;
if (maxHight<minHight){ //判断当前最大宽度
temp = minHight;
minHight = maxHight;
maxHight = temp;
}
count ++;
made(maxHight,land,minHight); //再次对折
}
}
}
别问我为什么写这个,我就是无聊了!!!!!!