题意分析:
解题分析:球走过的总距离,为 n=n+n/2 sum=100(1)+100/2(2)+100/4(3)+100/6(4) +······
知识点:while循环,
h=height 表示高度 h=h/2
d=distance 表示距离
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入数字n");
int n = sc.nextInt();
double h= 100;
double d = 100;
int i=0;
while(i<n) {
d=d+h; // 表示距离
h=h/2; // 表示高度
i++;
}
System.out.println("高度为" + d);
System.out.println("距离为" + h);
}
人生格言:不要指望事情会更容易,只能指望自己更强大