题解 | #小球走过路程计算#
小球走过路程计算
https://www.nowcoder.com/practice/ddbb7021c0a7452f9044564234616913
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
float h = scanner.nextFloat();
int n = scanner.nextInt();
double sum = 0;
for (int i = 0; i < n; i++) {
//计算球向下的总高度
sum += h;
//更新下一次高度
h = h / 2;
if (i == n - 1) {
System.out.println(String.format("%.3f", h) + " " + String.format("%.3f", sum));
}
//计算球总高度
sum += h;
}
//write your code here......
//输出格式为:System.out.println(String.format("%.3f", h)+" "+String.format("%.3f", sum));
}
}

