Example: Dialog: Kilometers to Miles

This program asks the user for a number of miles and converts it
to kilometers.

Dialog Input / Output

Convert String to a number.
We have to convert the input string to a number to do the arithmetic
with it.
This conversion is done by calling Double.parseDouble().
If we had wanted an integer instead of a double, we would have called Integer.parseInt().

Notes

Constant values are commonly declared static final before the methods are defined. The 'static' keyword will be explained later. If a variable is defined with the 'final' attribute, it's value can't be changed after an assignment to it, which is exactly what you want to do to prevent a constant from being changed.

You can only do arithmetic operations on numbers in Java, but showInputDialog returns a string. It's necessary to convert the string to a number. Here we convert the string to a double.