forked from RameshMF/Java-Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
28 lines (19 loc) · 941 Bytes
/
Copy pathMain.java
File metadata and controls
28 lines (19 loc) · 941 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
28
package modern.challenge;
import java.util.function.BinaryOperator;
public class Main {
public static void main(String[] args) {
int x = Integer.MAX_VALUE;
int y = Integer.MAX_VALUE;
int z = x * y;
System.out.println(x + " * " + y + " via '*' operator is: " + z);
long zFull = Math.multiplyFull(x, y);
System.out.println(x + " * " + y + " via Math.multiplyFull() is: " + zFull);
// throw ArithmeticException
int zExact = Math.multiplyExact(x, y);
System.out.println(x + " * " + y + " via Math.multiplyExact() is: " + zExact);
// throw ArithmeticException
BinaryOperator<Integer> operator = Math::multiplyExact;
int zExactBo = operator.apply(x, y);
System.out.println(x + " * " + y + " via BinaryOperator is: " + zExactBo);
}
}