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.