Results 1 to 8 of 8
  1. #1
    farahm is offline Member
    Join Date
    Nov 2010
    Location
    Beirut, Lebanon
    Posts
    36
    Rep Power
    0

    Default parsing command line arguments in java

    ok so when i used to enter an integer from the command line arguments i used to enter example: int num11 = Integer.parseInt(args[0]);
    now if i want to enter a word what do i use?
    thanks in advance for your help:)

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    All the command line parameters passes in a string array.

    Java Code:
    public static void main(String[] args)

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    In most of the reading materials of Java explains this as the first step. Did you ever notice that?

  4. #4
    farahm is offline Member
    Join Date
    Nov 2010
    Location
    Beirut, Lebanon
    Posts
    36
    Rep Power
    0

    Default

    this is not what i meant
    after the public static void main(String args[])
    {
    int num = Integer.parseInt(args[0]);
    }
    this i use to enter integers from the command what do i use to enter a word from the command line(integer). thanks in advance for your help

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by farahm View Post
    this is not what i meant
    after the public static void main(String args[])
    {
    int num = Integer.parseInt(args[0]);
    }
    this i use to enter integers from the command what do i use to enter a word from the command line(integer). thanks in advance for your help
    I think I don't understand your question; suppose I do this:

    Java Code:
    java YourProgram 1 foo 2 bar 3
    (I supplied five arguments: 1, foo, 2, bar and 3) What is your program supposed to do?

    kind regards,

    Jos
    Last edited by JosAH; 11-21-2010 at 02:05 PM. Reason: I can't count ...
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    farahm is offline Member
    Join Date
    Nov 2010
    Location
    Beirut, Lebanon
    Posts
    36
    Rep Power
    0

    Default

    never mind i found the answer i wanted thanks anyways. i just had to enter args[0] where i wanted the input to appear i didnt need parsing after all.

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Me too Jos, OPs question is not clear enough. Did he mean to passing command line arguments or passing values (reading form the console) from the command line. Anyway seem OP solved the problem.

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by farahm View Post
    never mind i found the answer i wanted thanks anyways. i just had to enter args[0] where i wanted the input to appear i didnt need parsing after all.
    If so please mark the thread solved.

Similar Threads

  1. command line arguments
    By evermore in forum New To Java
    Replies: 5
    Last Post: 03-28-2010, 05:08 AM
  2. java command line arguments
    By Vipul03 in forum Advanced Java
    Replies: 10
    Last Post: 02-25-2010, 10:12 AM
  3. java command line arguments
    By Vipul03 in forum New To Java
    Replies: 1
    Last Post: 02-22-2010, 02:00 PM
  4. arguments in command-line
    By girlet18 in forum New To Java
    Replies: 2
    Last Post: 01-21-2010, 02:05 PM
  5. Java Command Line Arguments In Eclipse IDE
    By JavaForums in forum Eclipse
    Replies: 0
    Last Post: 05-19-2007, 09:45 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
  •