Results 1 to 3 of 3
  1. #1
    Hevonen is offline Member
    Join Date
    Oct 2008
    Posts
    13
    Rep Power
    0

    Question Problem with Integer.parseInt()

    How to use Integer.parseInt() correctly?

    My code does not work:
    Java Code:
    class LeapYear{
       public static void main(String[] args) {
          String word = "1";
          System.out.println(Integer.parseInt("word") + 2);
       }
    }
    I am trying to convert the String variable word to integer.

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

    Default

    Your passing the String "word" to the parser, not the variable word. Get rid of the quotes.

  3. #3
    Hevonen is offline Member
    Join Date
    Oct 2008
    Posts
    13
    Rep Power
    0

Similar Threads

  1. [SOLVED] Command Line Arguments and ParseInt
    By Sophiie in forum New To Java
    Replies: 4
    Last Post: 11-16-2008, 10:45 PM
  2. Integer Usage
    By bluegreen7hi in forum New To Java
    Replies: 11
    Last Post: 01-24-2008, 09:54 AM
  3. VeryLong Integer.. help
    By hey in forum New To Java
    Replies: 4
    Last Post: 12-14-2007, 10:48 PM
  4. Integer vs int
    By bugger in forum New To Java
    Replies: 1
    Last Post: 11-14-2007, 10:13 PM
  5. Help with Integer in java
    By susan in forum New To Java
    Replies: 1
    Last Post: 07-14-2007, 06: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
  •