Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
4 views
in Java by (3.5k points)

Primitive Data Types - oracle doc says the range of long in Java is -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. But when I do something like this in my eclipse

long i = 12345678910;

it shows me "The literal 12345678910 of type int is out of range" error.

There are 2 questions.

1) How do I initialize the long with the value 12345678910?

2) Are all numeric literals by default of type int?

1 Answer

0 votes
by (46k points)
  1. You should add L: long i = 12345678910L;.
  2. Yes.

BTW: it doesn't have to be an upper case L, but lower case is confused with 1 many times :).

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Oct 27, 2019 in Java by Shubham (3.9k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...