-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkangaroo.java
More file actions
51 lines (42 loc) · 1.6 KB
/
kangaroo.java
File metadata and controls
51 lines (42 loc) · 1.6 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* There are two kangaroos on a number line ready to jump in the positive direction (i.e, toward positive infinity).
The first kangaroo starts at location x1 and moves at a rate of v1 meters per jump.
The second kangaroo starts at location x2 and moves at a rate of v2 meters per jump.
Given the starting locations and movement rates for each kangaroo, can you determine if they'll ever land at the
same location at the same time?
Input Format
A single line of four space-separated integers denoting the respective values of x1, v1, x2, and v2.
Output Format
Print YES if they can land on the same location at the same time; otherwise, print NO.
Note: The two kangaroos must land at the same location after making the same number of jumps. */
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
static String kangaroo(int x1, int v1, int x2, int v2) {
try
{
double t;
t = ((x2-x1)*10.00)/((v1-v2)*10.00);
//System.out.println(t);
if(t>=0 && t%1.00==0.00)
return "YES";
else
return "NO";
}
catch(Exception e)
{
return "NO";
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int x1 = in.nextInt();
int v1 = in.nextInt();
int x2 = in.nextInt();
int v2 = in.nextInt();
String result = kangaroo(x1, v1, x2, v2);
System.out.println(result);
}
}