题解 | #小球走过路程计算#
小球走过路程计算
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(); //write your code here...... float sum = h; float a = h; double num = Math.pow(2,n); float height = (float) (h / num); for(int i = 1;i < n;i++){ a = a / 2; sum += (a * 2); } System.out.println(String.format("%.3f", height)+" "+String.format("%.3f", sum)); } }