Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
05-17-2006, 01:13 AM #1
- Join Date
- Oct 2003
- Thanked 0 Times in 0 Posts
Got a question about declaring variables
If this is part of my code:
double costKwhr = Double.parseDouble(costKwhrField.getText());
double consumedKwhr = Double.parseDouble(hoursPerYearField.getText());
would I need to declare: costKwhr and hoursPerYear as doubles?
05-17-2006, 04:03 AM #2
- Join Date
- May 2002
- Marion, IA USA
- Thanked 83 Times in 82 Posts
Well to answer that with a question....If you are parsing a string using the parseDouble method which returns whatever it parses as datatype of double and you want to assign that resulting data that is of datatype double to another variable what datatype should the variable probably need to be to handle data of type double?
You already have costKwhr declared as a double. As for hoursPerYear I assume you meant hoursPerYearField then it is obviously a variable that is going to be holding a string. It looks to be part of the TextComponent class judging from the .getText() method that goes with it. Not sure why you would think that needs to be declared a double. It is actually a reference to the object you created from that TextComponent class and not a variable.
CodingForums Supreme Overlord
All Hail Spookster