how to convert kilometers to miles in java

how to convert kilometers to miles in java

To convert kilometers to miles in Java, you can use the following formula:

r‮fe‬er to:lautturi.com
miles = kilometers * 0.621371

This formula converts a distance in kilometers to the equivalent distance in miles.

Here is an example of how you can use this formula to convert kilometers to miles in Java:

double kilometers = 100.0;
double miles = kilometers * 0.621371;
System.out.println(miles);

This code defines a double variable called kilometers and assigns it the value 100.0, and then uses the conversion formula to calculate the equivalent distance in miles and store it in a double variable called miles. Finally, the code prints the value of the miles variable to the console.

The output of this code will be 62.1371, which is the equivalent distance in miles for a distance of 100 kilometers.

Note that this formula is an approximation, and the actual conversion factor may vary slightly depending on the definition of the mile used. The conversion factor used in this formula is based on the international mile, which is defined as 1,609.344 meters.

Created Time:2017-11-01 12:05:15  Author:lautturi