Niuke.com|Find the distance and rebound height of the ball after 5 times of landing

Topic information

Suppose a ball falls freely from any height, and bounces back to half of its original height after each landing. If it falls again, how many meters does it experience on the fifth landing? How high is the fifth rebound?

The initial height is int type, and the final error judgment is 6 decimal places.

answer

As shown in the figure below, the initial height is height, the green height is the distance of each landing, and the yellow background is the height of each bounce.

The total height of 5 landings is: height + height/2 + height/2 + height/4 + height/4 + height/8 + height/8 + height/16 + height/16 = 23height/8

The height of the 5 rebounds is: height/32

coding

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class BallFall {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String input;
		while((input = br.readLine()) != null) {
			double startHeight = Integer.parseInt(input);
			double sumHeight = 23 * startHeight / 8;
			System.out.println(sumHeight);
			double reverseFall = startHeight / 32;
			System.out.println( reverseFall);
		}
	}
}

 

Guess you like

Origin blog.csdn.net/magi1201/article/details/114776494