Frog Jump Program  

by ne on 2021-03-02 under Algo

A small frog is standing at a given position X, and he wants to jump to/after a position Y, given that his one jump is of D units. Find how many jumps will it require to get to OR cross Y.

For example, if X=10, Y=85 and D=30. Then it would take 3 jumps => 10 + 30 + 30 + 30 = 100.

Please try it out yourself first, before moving on to the solution.

Solution:


public class SolutionFrogJump {
    public int solution(int X, int Y, int D){
        return (int)Math.ceil((double)(X+Y)/D);
    }
    public static void main(String[] arg){

        int ret=new SolutionFrogJump().solution(0,100,30);
        System.out.println(ret);

    }
}