1 //题目:一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下, 2 //求它在 第10次落地时,共经过多少米?第10次反弹多高? 3 //1.经过多少米是一个累加的过程 2.递归的思想 4 //1.double 2.不要复杂化 5 public class Ziyou{ 6 static double distance=100; 7 static double height =100; 8 public static void main(String[] args) { 9 for(int i=1;i<10;i++) { 10 distance +=height; 11 height=height/2; 12 } 13 System.out.println("路程:" + distance); 14 System.out.println("高度:" + height / 2); 15 } 16 17 }
1 路程:299.609375 2 高度:0.09765625