public static void main(String[] args) {
int n = 1; // 次数计数器
double h = 100; // 总高度
double s = 0; // 共经过的路程
while(n <= 10)
{
s += h;
h /= 2;
n ++;
}
intln("the length is: " + s + "m");
intln("the last height is: " + h + "m");
}
运行结果:
the length is: 199.8046875m
the last height is: 0.09765625m