public class Three { public static void main(String[] args) { Three obj = new Three(); obj.function(600851475143); } private Long function(long i) { Stack<Long> stack = new Stack<Long>(); for (long j = 2; j <= i; j++) { if (i % j == 0) { stack.push(j); } } return stack.pop(); } }
When the code above is run, it produces an error on the line obj.function(600851475143);
. Why?
If you are dealing with numbers in your Java program and it gets too long! (over 2,147,483,647 to be precise) then it a type long and not int so you need to suffix the letter capital L or lower case l to fix the compilation error.
long: The long data type is a 64-bit two's complement integer. The signed long has a minimum value of -263 and a maximum value of 263-1. In Java SE 8 and later, you can use the long data type to represent an unsigned 64-bit long, which has a minimum value of 0 and a maximum value of 264-1.
600851475143
cannot be represented as a 32-bit integer (type int
). It can be represented as a 64-bit integer (type long
). long literals in Java end with an "L": 600851475143L
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With