# Java Program to Convert Kilometers to Miles

In this post, we will learn to code the Java Program to Convert Kilometers to Miles. Let’s understand more about Kilometers to Miles conversion and How to Convert Kilometers to Miles in Java Programming Language.

## What is KIlometers?

A Kilometer is a unit of length in the metric system, which is equal to one thousand meters. It is now the measurement unit used for expressing distances between geographical places on land in most of the world. The SI symbol of a Kilometer is Km.

## What is Miles?

A mile is also a unit of length but it is popular in the imperial and US customary systems of measurement. It is currently defined as 5,280 feet, 1,760 yards, or exactly 1609.344 meters i.e. 1.609344 Km. The symbol of a mile is mi.

### Kilometers (Km) to Miles (mi) Conversion

1 Mile is exactly equal to 1609.344 meters which are when converted in kilometers is equal to 1.609344 Km.
Therefore,
1 Mile = 1.609344 Kilometers

So, 1 Km = 1/1.609344 = 0.6213711922 miles

``1 kilometer = 0.6213711922 miles``

Now, let’s see the Java Program to Convert Kilometers to Miles.

## Java Program to Convert Kilometers to Miles

```import java.util.*;

public class Main{

public static void main(String[] args){

Scanner sc = new Scanner(System.in);

System.out.println("Enter the Distance in Kilometers: ");
float km = sc.nextFloat();

//Kilometers to miles conversion
float miles = (float)(0.6213711922 * km);

System.out.println("Distance in miles will be: "+miles);

}

}```

Output 1

``````Enter the Distance in Kilometers: 100
Distance in miles will be: 62.13712``````

Output 2

``````Enter the Distance in Kilometers: 1.609344
Distance in miles will be: 1.0``````

## How Does This Program Work ?

```        Scanner sc = new Scanner(System.in);
System.out.println("Enter the Distance in Kilometers: ");
float km = sc.nextFloat();```

In this Program, first, we take the input of the distance in Kilometers(Km) from the user as input using the Scanner Class in Java.

```        //Kilometers to miles conversion
float miles = (float)(0.6213711922 * km);```

Then, we convert the distance from Kilometers to Miles by multiplying 0.6213711922 to the distance in kilometers. Here, we have done the explicit type casting to float as 0.6213711922 is a double value so we converted the value to float explicitly.

`        System.out.println("Distance in miles will be: "+miles);`

Then, we display the result using the `System.out.println()` function.

This is the Java Program to Convert Kilometers to Miles.

Read More : Java Program to Convert Miles to Kilometers

## Conclusion

I hope after going through this post, you understand the Java Program to Convert Kilometers to Miles.
If you have any doubt regarding the topic, feel free to contact us in the Comment Section. We will be delighted to help you.