How can I get a long number bigger than Long.MAX_VALUE?
I want this method to return true:
boolean isBiggerThanMaxLong(long val) {
r
Firstly, the below method doesn't compile as it is missing the return type and it should be Long.MAX_VALUE in place of Long.Max_value.
public static boolean isBiggerThanMaxLong(long value) {
return value > Long.Max_value;
}
The above method can never return true as you are comparing a long value with Long.MAX_VALUE , see the method signature you can pass only long there.Any long can be as big as the Long.MAX_VALUE, it can't be bigger than that.
You can try something like this with BigInteger class :
public static boolean isBiggerThanMaxLong(BigInteger l){
return l.compareTo(BigInteger.valueOf(Long.MAX_VALUE))==1?true:false;
}
The below code will return true :
BigInteger big3 = BigInteger.valueOf(Long.MAX_VALUE).
add(BigInteger.valueOf(Long.MAX_VALUE));
System.out.println(isBiggerThanMaxLong(big3)); // prints true