In this section, you will learn to convert Miles to
Kilometers. The following program helps you in converting Miles to
Kilometers.
Code Description:
To convert Miles to
Kilometers we have used a formula "km = miles * 1.609344;". The
compiler will ask to enter the number of Miles from the keyboard due to the
method "BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));".
Here we have taken miles to be of type float. To avoid loss of precession
we have cast the output to be in float.
Here is the code of the program:
|
Output of the program:
| C:\unique>javac MilesToKms.java C:\unique>java MilesToKms Enter a number of miles: 1 1.0 miles is 1.609344 kilometers. C:\unique> |
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Convert Miles To Kilometers
Post your Comment