Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By SurfMan

Thread: Why is "int var = 24,000;" wrong?

  1. #1
    ghandil is offline Member
    Join Date
    Jun 2013
    Posts
    28
    Rep Power
    0

    Default Why is "int var = 24,000;" wrong?

    Hi,
    Why does compiler throw error: <identifier> expected on this declaration:

    Java Code:
    int var = 24,000;
    and how to fix it?

    Thanks

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Why is "int var = 24,000;" wrong?

    You can't have commas in a number. However, you can use an underscore to act as digit separators. In your case:

    Java Code:
    int var = 24_000;
    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    ghandil is offline Member
    Join Date
    Jun 2013
    Posts
    28
    Rep Power
    0

    Default Re: Why is "int var = 24,000;" wrong?

    Quote Originally Posted by jim829 View Post
    You can't have commas in a number. However, you can use an underscore to act as digit separators. In your case:

    Java Code:
    int var = 24_000;
    Regards,
    Jim
    Thanks,
    But what does this have to do with identifier? the var is the identifier there, I think.

  4. #4
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,995
    Rep Power
    9

    Default Re: Why is "int var = 24,000;" wrong?

    var is indeed the identifier, but in Java you can have mulitple variables initialized on the same line. This is separated by a comma. But there is no variable after the comma. That's why the compiler is confused. This is valid:
    Java Code:
    int a=4, b=5;
    If you compare it to your code, you can see why the compiler expects a indentifier after the comma.
    jim829 likes this.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  5. #5
    ghandil is offline Member
    Join Date
    Jun 2013
    Posts
    28
    Rep Power
    0

    Default Re: Why is "int var = 24,000;" wrong?

    Thanks Surfman. I get it now.

Similar Threads

  1. Replies: 0
    Last Post: 12-07-2012, 09:29 AM
  2. Replies: 3
    Last Post: 10-30-2012, 04:06 PM
  3. Replies: 2
    Last Post: 07-25-2011, 08:22 AM
  4. Replies: 2
    Last Post: 01-24-2009, 07:56 PM
  5. Replies: 1
    Last Post: 10-20-2008, 08:35 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
  •