0

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.

class Sum {
    static public void main(String args[]){
        long num=600851475143;
    }
}
4
  • 2
    Note that it is standard practice to put public before static: public static void main(...) Commented Feb 16, 2013 at 19:06
  • When asking questions, remember to also post the real [compiler] error message and, better, search for the error before asking a question .. Commented Feb 16, 2013 at 19:11
  • stackoverflow.com/questions/3757763/… , stackoverflow.com/questions/8924896/… - from [java] integer too large search .. Commented Feb 16, 2013 at 19:13
  • I wll take care of it... Thank you,assylias Commented Feb 20, 2013 at 13:44

2 Answers 2

9

append 'L' or 'l' at the end of the number to make it a long literal.you can use both lowercase(l)or uppercase(L), but uppercase(L) is recommend for readability.

 long num=600851475143L;
Sign up to request clarification or add additional context in comments.

Comments

3

An integer literal is of type long if it ends with the letter L or l; otherwise it is of type int. It is recommended that you use the upper case letter L because the lower case letter l is hard to distinguish from the digit 1.

Reference

So use this -

long num=600851475143l;

or better

long num=600851475143L;

3 Comments

I prefer a capital L, because l looks to similar to 1.
Actually it is recommended. :)
I know. Wrote the comment long before you mentioned it in the answer ;)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.