-
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
-
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");
}
-
Hey you shouldn't use javac for running your classes (I'm sure you justed typed wrong, I'm telling you just in case)