Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Test {
- public static int bouncingBall(double h, double bounce, double window) {
- if (window > h || h < 0 || bounce >= 1 || bounce < 0) // note >=
- return -1;
- int viewCount=1; // initial fall
- double height =h*bounce; // height of bounce
- while (height>window)
- {
- height=height*bounce;
- viewCount+=2; // going up and down
- }
- return viewCount;
- }
- public static void main(String[] args) {
- System.out.println( bouncingBall(3, 0.66, 1.5)); //3
- System.out.println( bouncingBall(3, 1, 1.5)); //-1
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment