-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrogJumps.java
More file actions
32 lines (23 loc) · 768 Bytes
/
FrogJumps.java
File metadata and controls
32 lines (23 loc) · 768 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* Created by Vatsal on 15-Jul-16.
* PROBLEM: Given the current position(x) of a frog and destination(y),
* compute the number of jumps required to reach from x to y,
* if the covers D blocks in a single jump.
*/
class FrogJumps {
public int solution(int x, int y, int D){
int jumps;
if(x==y) return 0;
else{
int distance = Math.abs((y-x));
if(distance%D==0) jumps = distance/D;
else jumps = (distance/D)+1;
return jumps;
}
}
public static void main(String[] args) {
FrogJumps t = new FrogJumps();
int jumps = t.solution(0, 10, 3);
System.out.println("No. of jumps = "+jumps);
}
}