Results 1 to 3 of 3

Thread: command line arguments

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    command line arguments

    Hello

    I am trying to use command line arguments to enter some float variables.

    But l am unsure whether the command line arguments will accept anything else other than a string.

    My code for this:
    [code]

    //Create a pool object from the class SwimmingPool, parameters
    //to the constructor

    Swimming pool = new SwimmingPool(args[0],args[1],args[2],args[3]);

    [\code]

    when l compile l use this
    javac pool 10.0 15.0 10.0 20.0

    and get a error message.

    public static void main(String[] args)
    instead of this could have float instead of string.

    If his does not work, is there a way to convert a string data type to a float data type, that would work for me.

    Many thanks in advance
    steve

  2. #2
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724
    Code:
    float temp = 0;
    String parse = "123.456";
    		
    try 
    {
        temp = Float.parseFloat(parse);
        System.out.println(temp);
    }
    catch (NumberFormatException nfe)
    {
        System.out.println("Invalid number");
    }

  3. #3
    Lively Member J Lindroos's Avatar
    Join Date
    Mar 2001
    Location
    Sweden
    Posts
    97
    Hey you shouldn't use javac for running your classes (I'm sure you justed typed wrong, I'm telling you just in case)
    /J Lindroos
    "My opinions may be have changed, but not the fact that I am right"


    <modified by admin. no advertising in sigs>

Posting Permissions

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



Click Here to Expand Forum to Full Width