Knowing that
- A is the starting point
- B is the destination point
- D is the step size
Assume that
- A, B and D are integers and > 0;
- A ≤ B.
public int calc(int A, int B, int D) {
if ( A == B ) return 0;
int dist = B - A;
int steps = dist/D;
if ( dist%D !=0 ){
steps +=1;
}
return steps;
}