import java.util.Scanner;
public class BallDown {
public static void main(final String[] args) {
double sum = 0;
double high = 100;
Scanner sc = new Scanner(System.in);
System.out.println("你想知道小球第n次落地时经过的距离和之后反弹高度,就输入数字n");
int n = sc.nextInt();
for (int x = 1; x <= n; x++) {
sum += (high * 2);
high /= 2;
}
System.out.println("第" + n + "落地时小球经过的距离是" + (sum - 100) + "m");
System.out.println("第" + n + "次落地后反弹高度是" + high + "m");
sc.close();
}
}
|