Click here to Skip to main content
15,908,634 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am writing a code in which I am trying to assign a value in long variable.
But java compiler is showing error that too large integer number.
I am trying to store 600851475143 in long type still.
:::code:::
class Sum
{
static public void main(String args[])
{
long num=600851475143;
}
}


Please help..... :(
Posted

Hello

you need to add an L at the end of the number.

C#
class Sum
{
static public void main(String args[])
{
long num=600851475143L;
}
}



Valery.
 
Share this answer
 
For explicit setting of long values you should append a 'L' otherwise the compiler will take it as an int and it will overflow:
Java
long num=600851475143L;
 
Share this answer
 
Comments
Valery Possoz 16-Feb-13 14:06pm    
You were faster than me :)
Mehdi Gholam 17-Feb-13 0:19am    
:)
Sergey Alexandrovich Kryukov 16-Feb-13 19:30pm    
Ha-ha, a 5.
—SA
Mehdi Gholam 17-Feb-13 0:18am    
Cheers Sergey!
Sergey Alexandrovich Kryukov 17-Feb-13 0:26am    
:-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900