• Post Reply Bookmark Topic Watch Topic
  • New Topic

The literal 600851475143 of type int is out of range  RSS feed

 
shishir dwivedi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am declaring literal 300425737572 as long then compiler through the error that literal of type int is out of range.
when i am using long how could compiler think that it is int.
here is the code

long number=300425737572;
how to solve this problem ?
please help.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you need to put an "L" on the end of your literal:

long number=300425737572L;

Literals are (again, I think) ints by default, and this is too big for an int.
 
Greg Charles
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Long literalis in Java must end with L, so 300425737572L.

ETA: ninja'd. It's what Fred said.
 
Greg Charles
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shishir dwivedi,
Your post was moved to a new topic.
split off new question
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!