-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCLOSE_FAR.java
More file actions
27 lines (22 loc) · 751 Bytes
/
CLOSE_FAR.java
File metadata and controls
27 lines (22 loc) · 751 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
/*
Given three ints, a b c, return true if one of b or c is "close" (differing from a by at most 1),
while the other is "far", differing from both other values by 2 or more.
Note: Math.abs(num) computes the absolute value of a number.
closeFar(1, 2, 10) → true
closeFar(1, 2, 3) → false
closeFar(4, 1, 3) → true
*/
package school;
public class CLOSE_FAR {
public static void main(String[] args){
boolean answer = closeFar(1,2,10);
System.out.println(answer);
}
public static boolean closeFar(int a, int b, int c) {
if((Math.abs(a-b)<=1) && (Math.abs(a-c)>=2)&& (Math.abs(b-c)>=2)){
return true;
}else if((Math.abs(a-c)<=1) && (Math.abs(a-b)>=2) && (Math.abs(b-c)>=2)){
return true;
}return false;
}
}