**1.61E+06: **In the previous article we have discussed about Java Program to Convert Millimeter to Nanometer and Nanometer to Millimeter

In this article we will see how to convert Millimeter to Mile and Mile to Millimeter by using Java programming language.

## Java Program to Convert Millimeter to Mile and Mile to Millimeter

Before jumping into the program let’s know the relationship between Millimeter and Mile.

Generally Millimeter is used to measure very small length mainly we use to measure visible scale distances and Mile is used to measure distance.

1 Millimeter = 6.21371e-7 Mile 1 Mile = 1.609e+6 Millimeter

Formula to convert Millimeter to Mile.

Mile = Millimeter / 1.609e+6

Formula to convert Mile to Millimeter.

Millimeter = Mile * 1.609e+6

Let’s see different ways to convert Millimeter to Mile and Mile to Millimeter.

### Method-1: Java Program to Convert Millimeter to Mile and Mile to Millimeter By Using Static Input Value

**Approach:**

- Declare Millimeter and Mile value.
- Then convert Millimeter to Mile and Mile to Millimeter by using the formula.
- Print result.

**Program:**

import java.util.*; public class Main { public static void main(String args[]) { //Scanner class object created Scanner sc=new Scanner(System.in); //value of mile declared double mile = 1; //value of millimeter declared double millimeter = 1; //converting millimeter to mile double mi = millimeter / 1.609e+6; //converting mile to millimeter double mm = mile * 1.609e+6; //printing result System.out.println("Value of "+mile+" mile in millimeter: "+ mm); System.out.println("Value of "+millimeter+" millimeter in mile: "+ mi); } }

Output: Value of 1.0 mile in millimeter: 1609000.0 Value of 1.0 millimeter in mile: 6.215040397762585E-7

### Method-2: Java Program to Convert Millimeter to Mile and Mile to Millimeter By Using User Input Value

**Approach:**

- Take user input of Millimeter and Mile value.
- Then convert Millimeter to Mile and Mile to Millimeter by using the formula.
- Print result.

**Program:**

import java.util.*; public class Main { public static void main(String args[]) { //Scanner class object created Scanner sc=new Scanner(System.in); //Taking the value input of double variable mile System.out.println("Enter value of mile: "); double mile = sc.nextDouble(); //Taking the value input of double variable millimeter System.out.println("Enter value of millimeter: "); double millimeter = sc.nextDouble(); //converting millimeter to mile double mi = millimeter / 1.609e+6; //converting mile to millimeter double mm = mile * 1.609e+6; //printing result System.out.println("Value of "+mile+" mile in millimeter: "+ mm); System.out.println("Value of "+millimeter+" millimeter in mile: "+ mi); } }

Output: Enter value of mile: 2 Enter value of millimeter: 900000 Value of 2.0 mile in millimeter: 3218000.0 Value of 900000.0 millimeter in mile: 0.5593536357986327

### Method-3: Java Program to Convert Millimeter to Mile and Mile to Millimeter By Using User Defined Method

**Approach:**

- Take user input of Millimeter and Mile value.
- Call a user defined method by passing Millimeter and Mile value as parameter.
- Inside method convert Millimeter to Mile and Mile to Millimeter by using the formula.
- Print result.

**Program:**

import java.util.*; public class Main { public static void main(String args[]) { //Scanner class object created Scanner sc=new Scanner(System.in); //Taking the value input of double variable mile System.out.println("Enter value of mile: "); double mile = sc.nextDouble(); //Taking the value input of double variable millimeter System.out.println("Enter value of millimeter: "); double millimeter = sc.nextDouble(); //calling user defined method convert() convert(mile, millimeter); } //convert() method to convert mile to millimeter and vice versa public static void convert(double mile, double millimeter) { //converting millimeter to mile double mi = millimeter / 1.609e+6; //converting mile to millimeter double mm = mile * 1.609e+6; //printing result System.out.println("Value of "+mile+" mile in millimeter: "+ mm); System.out.println("Value of "+millimeter+" millimeter in mile: "+ mi); } }

Output: Enter value of mile: 5 Enter value of millimeter: 999999 Value of 5.0 mile in millimeter: 8045000.0 Value of 999999.0 millimeter in mile: 0.6215034182722188

The best and excellent way to learn a java programming language is by practicing Simple Java Program Examples as it includes basic to advanced levels of concepts.

**Related Java Programs:**