How to use long data type in Java?

I need to use a fairly large number - 600851475143; as we all know, I have to use a long data type, but when I try to initialize like: long number = 600851475143 I get an error message:

The literal 600851475143 of type int is out of range.

I don't seem to know how to use the long data type correctly.

+6
source share
3 answers
 long number = 600851475143L 

Use "L" to make it a long type.

+17
source

Use "L" to make it long. By default, the whole variable of integer type (byte, int, long) is "int"

 long num=600851475143L; 

or

 long num=600851475143l; // small 'L' 
+5
source

Use

  long number = 600851475143L; 
+2
source

Source: https://habr.com/ru/post/949456/


All Articles