Results 1 to 4 of 4
  1. #1
    Zigster is offline Member
    Join Date
    Apr 2012
    Posts
    74
    Rep Power
    0

    Default The literal of type int is out of range?

    Hello, I've just started a new piece of code and am getting an error already:

    The literal 600851475143 of type int is out of range

    Java Code:
    public class Problem3 {
    	public static void main (String args[]){
    		
    		long y, x;
    		y=600851475143;
    		for (x=0,x<600851475143,x++){
    			
    		}
    	}
    
    }
    The error is for the number:600851475143. Am I using long incorrectly?

    Cheers!

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: The literal of type int is out of range?

    You're forgetting the "L" that needs to be appended to the end of a long literal:

    Java Code:
    public class Problem3 {
        public static void main (String args[]) {
             
            long y = 600851475143L;
            for (long x = 0L; x < 600851475143L; x++) {
    
            }
        }
    
    }
    You're also forgetting to add spaces to your code. :)

    edit: and semicolons in the for condition
    Last edited by Fubarable; 04-24-2012 at 04:32 AM.

  3. #3
    jlczuk is offline Senior Member
    Join Date
    Apr 2012
    Location
    New York State of Confusion, USA
    Posts
    137
    Blog Entries
    1
    Rep Power
    0

    Default Re: The literal of type int is out of range?

    There are limits to the values that can be stored in the various numeric data types. You should read the Primitive Data Types Tutorial to understand them.

    Beaten by the Fubarable...I'm going to bed!

  4. #4
    Zigster is offline Member
    Join Date
    Apr 2012
    Posts
    74
    Rep Power
    0

    Default Re: The literal of type int is out of range?

    Thanks! Solved!

Similar Threads

  1. Change Literal String to File Path with speratorChar
    By Jeremiah in forum New To Java
    Replies: 2
    Last Post: 08-18-2011, 08:14 PM
  2. Replies: 2
    Last Post: 02-04-2011, 11:10 PM
  3. Replies: 3
    Last Post: 03-26-2010, 08:09 AM
  4. Regex - matching literal characters
    By racha0601 in forum Advanced Java
    Replies: 3
    Last Post: 04-08-2009, 12:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •