Java写题解的第4天 | #求小球落地5次后所经历的路程和第5次反弹的高度#
求小球落地5次后所经历的路程和第5次反弹的高度
http://www.nowcoder.com/practice/2f6f9339d151410583459847ecc98446
解题思路:模拟
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s = ""; while ((s = br.readLine()) != null) { double height = Double.parseDouble(s); // length at 1st get ground double length = height + 0.0; for (int i = 2; i <= 5; i++) { length += height; height /= 2; } System.out.println(length); System.out.println(height/2); } br.close(); } }