waltermilner

Untitled

Dec 17th, 2015
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.64 KB | None | 0 0
  1. public class Test {
  2.  
  3.   public static int bouncingBall(double h, double bounce, double window) {  
  4.            if (window > h || h < 0 || bounce >= 1 || bounce < 0) // note >=
  5.            return -1;
  6.          int viewCount=1; // initial fall
  7.          double height =h*bounce; // height of bounce
  8.          while (height>window)
  9.          {
  10.            height=height*bounce;
  11.            viewCount+=2; // going up and down
  12.          }
  13.          return viewCount;
  14.          
  15.         }
  16.  
  17.   public static void main(String[] args) {
  18.  
  19.     System.out.println( bouncingBall(3, 0.66, 1.5)); //3
  20.      System.out.println( bouncingBall(3, 1, 1.5)); //-1
  21.   }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment