View Single Post
  #4 (permalink)  
Old 06-23-2009, 09:30 PM
porchrat porchrat is offline
Member
 
Join Date: Mar 2009
Posts: 41
Rep Power: 0
porchrat is on a distinguished road
Default
IMO it is always a good idea to initialise your variables in the beginning and not just declare them (as you have done).

instead of:
Code:
int initialAmount;
double convertedAmount;
use:
Code:
int initialAmount = 0;
double convertedAmount = 0.0;
You can't always count on default values.

That will solve the error, but that means that whenever this condition is not met:
Code:
if(fromUnit.equals("centimeter") && toUnit.equals("feet"))
Your program will then print out the 0.0 value, which is obviously not desirable. To prevent that you would need to complete the class and ensure that you have an 'else' statement at the end.
Reply With Quote