Time until distance gets equal to X between two objects moving in opposite direction | Java implementation of the approach ; Function to return the time for which the two policemen can communicate ; time = distance / speed ; Driver code
class GFG { static double getTime ( int u , int v , int x ) { double speed = u + v ; double time = x / speed ; return time ; } public static void main ( String [ ] args ) { int u = 3 , v = 3 , x = 3 ; System . out . println ( getTime ( u , v , x ) ) ; } }