Number of hours after which the second person moves ahead of the first person if they travel at a given speed | Java implementation of the above approach ; Function to return the number of hours for the second person to move ahead ; Time taken to equalize ; Time taken to move ahead ; Driver code
import java . io . * ; class GFG { static int findHours ( int a , int b , int k ) { if ( a >= b ) return - 1 ; int time = k / ( b - a ) ; time = time + 1 ; return time ; } public static void main ( String [ ] args ) { int a = 4 , b = 5 , k = 1 ; System . out . println ( findHours ( a , b , k ) ) ; } }