-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem16.java
More file actions
17 lines (15 loc) · 867 Bytes
/
Problem16.java
File metadata and controls
17 lines (15 loc) · 867 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/*Write the method below that takes four integer arguments and returns true if and only if at
least three of the four values are the same. For example, if the values passed in are 5, 3, 5, 5, it would
return true. If the values passed in are 7, 3, 7, 9, it would return false. */
public class Problem16 {
public static void main(String[] args) {
int a = (int)(Math.random() * 10);
int b = (int) (Math.random() * 10);
int c = (int) (Math.random() * 10);
int d = (int) (Math.random() * 10);
System.out.println("It is " + atLeastThreeMatch(a, b, c, d) + " that at least three are the same. " + a + " " + b + " " + c + " " + d);
}
public static boolean atLeastThreeMatch(int a, int b, int c, int d) {
return (a == b && a == c) || (a == b && a == d) || (a == c && a == d) || (b == c && b == d);
}
}