EN
Java - get int min value
10 points
Short solution:
xxxxxxxxxx
1
int MIN_VALUE = Integer.MIN_VALUE;
2
3
System.out.println(MIN_VALUE); // -2147483648
Java Integer min value is -2,147,483,648.
Short solution to get int max value:
xxxxxxxxxx
1
int MAX_VALUE = Integer.MAX_VALUE;
2
3
System.out.println(MAX_VALUE); // 2147483647
Java Integer max value is 2,147,483,647.
xxxxxxxxxx
1
public class Example1 {
2
3
public static void main(String[] args) {
4
5
int MIN_VALUE = Integer.MIN_VALUE;
6
System.out.println(MIN_VALUE); // -2147483648
7
8
int MIN_VALUE_2 = (int) Math.pow(2, 31) + 1;
9
System.out.println(MIN_VALUE_2); // -2147483648
10
11
int MIN_VALUE_3 = -1 << 31;
12
System.out.println(MIN_VALUE_3); // -2147483648
13
14
int MIN_VALUE_4 = ~(~0 >>> 1);
15
System.out.println(MIN_VALUE_4); // -2147483648
16
}
17
}
Output:
xxxxxxxxxx
1
-2147483648
2
-2147483648
3
-2147483648
4
-2147483648
xxxxxxxxxx
1
public class Example2 {
2
3
public static void main(String[] args) {
4
5
int MIN_VALUE = Integer.MIN_VALUE;
6
int overflow = MIN_VALUE - 100;
7
System.out.println(overflow); // 2147483548
8
}
9
}
Output:
xxxxxxxxxx
1
2147483548