Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use long data type in Java? [duplicate]

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

The literal 600851475143 of type int is out of range.

It seems that I don't know how to use long data type correctly.

like image 584
Paulius Avatar asked Jul 15 '13 09:07

Paulius


People also ask

Which data type does not contain duplicate value?

HASHTABLE is a structure of Key value pairs.. Here what the values passed by the SET is treated as Keys of HASHTABLE Internally. keys are unique cannot be duplicated.

What is a long data type in Java?

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.


2 Answers

long number = 600851475143L

Use "L" to make it as long type

like image 121
RaceBase Avatar answered Feb 01 '23 23:02

RaceBase


Use "L" to make it as long type. By default all integer type variable(byte,int,long) is "int"

long num=600851475143L;

or

long num=600851475143l; // small 'L'
like image 34
Naren Avatar answered Feb 02 '23 00:02

Naren