Thursday, July 30, 2009

Java Problem?

I'm currently learning Java and have been reading an eBook covering every aspect of it for the last few days. Every now and then in this eBook it tells you to write and compile what it tells you to with only little detail as you go further in it. Currently, I'm on a chapter that explains variables and this is what it says: "Write a public class called TempConverter and declare the main() method within the class.". "The value for Fahrenheit will be input from the command line. Because all command-line arguments are String objects, the first thing you need to do within main() is convert the String to a double. Use the following statement, which converts the first command-line argument into a double: double F = Double.parseDouble(args[0]);" and then it says the formula for converting Celsius to Fahrenheit is C = ( 5 / 9) x (F - 32). What I've done is declared the public static void main(String[] args); then have no idea what to do next lol.. any help would be appreciated.

Java Problem?
Here's an example of string to double





String numString = "2.3";


double converted;


converted = Double.parseDouble(numString);





or alternatively





converted = Double.valueOf(numString).doubleValue();





EDIT: Your updated code has an error in it.





public static void main(String[] args);





should not have a semi-colon after it, as it is the beginning of a method and is not a statement on its own. A semi-colon denotes the end of a statement.

800flowers.com

No comments:

Post a Comment