将一个小球从100米抛下,假设它每次弹起之前一半的高度,求小球弹跳总高度和弹跳高度
/**
* @author Administrator jie
* @param count 弹跳次数
* @return 返回第count次弹起的高度
*/
public static double high(int count){
if(count==1){return 50;}
return high(count-1)/2;
}
/**
*
* @param count 弹跳次数
* @return 第count次弹跳结束时经过的路程
*/
public static double totalHigh(int count){
if(count==1){return 100+high(count)*2;}//第一次弹跳结束时经过的路程
return totalHigh(count-1)+high(count-1);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("请输入弹跳次数:");
int count = sc.nextInt();
System.out.println("第"+count+"次弹跳高度为:"+high(count)+"米");
System.out.println("第"+count+"次弹完总路程为:"+totalHigh(count)+"米");
}