forked from PacktPublishing/Java-Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
37 lines (23 loc) · 1.26 KB
/
Main.java
File metadata and controls
37 lines (23 loc) · 1.26 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
package modern.challenge;
import java.math.BigInteger;
public class Main {
public static void main(String[] args) {
BigInteger nr = BigInteger.valueOf(Long.MAX_VALUE);
long nrLong = nr.longValue();
System.out.println(nr + " as long is: " + nrLong);
int nrInt = nr.intValue();
System.out.println(nr + " as int is: " + nrInt);
short nrShort = nr.shortValue();
System.out.println(nr + " as short is: " + nrShort);
byte nrByte = nr.byteValue();
System.out.println(nr + " as byte is: " + nrByte);
long nrExactLong = nr.longValueExact(); // ok
System.out.println(nr + " as exact long is: " + nrExactLong);
int nrExactInt = nr.intValueExact(); // ArithmeticException
System.out.println(nr + " as exact int is: " + nrExactInt);
short nrExactShort = nr.shortValueExact(); // ArithmeticException
System.out.println(nr + " as exact short is: " + nrExactShort);
byte nrExactByte = nr.byteValueExact(); // ArithmeticException
System.out.println(nr + " as exact byte is: " + nrExactByte);
}
}