# Java Program to Convert Meter to Mile and Mile to Meter

In the previous article, we have seen Java Program to Convert Miles to Kilometers and Kilometers to Miles

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

## Java Program to Convert Meter to Mile and Mile to Meter

Formula to convert Meter to Mile

Miles = Meter * 0.000621371

Formula to convert Mile to Meter

Meters = Mile * 1609.34

Let’s see different ways to convert meter to mile and mile to meter.

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

Approach:

• Declare miles and meters value.
• Then using formula convert miles to meter and vice versa.
• Print the result.

Program:

import java.util.*;
public class Main
{
public static void main(String args[])
{
//Scanner class object created
Scanner sc=new Scanner (System.in);
//meter value
double meterValue=4;
//mile value
double mileValue=0.002456789;

//converting meter to mile
double mile= meterValue * 0.000621371;
//converting mile to meter
double meter= mileValue * 1609.34;

//printing result
System.out.println("After converting meter to mile: "+mile);
System.out.println("After converting mile to meter: "+meter);
}
}
Output:

After converting meter to mile: 0.002485484
After converting mile to meter: 3.95380880926

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

Approach:

• Take input of miles and meters value.
• Then using formula convert miles to meter and vice versa.
• Print the 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 input of meter value
System.out.println("Enter meter to convert into mile: ");
double meterValue=sc.nextDouble();
//taking input if mile value
System.out.println("Enter mile to convert into meter: ");
double mileValue=sc.nextDouble();

//converting meter to mile
double mile= meterValue * 0.000621371;
//converting mile to meter
double meter= mileValue * 1609.34;

//printing result
System.out.println("After converting meter to mile: "+mile);
System.out.println("After converting mile to meter: "+meter);
}
}
Output:

Enter meter to convert into mile:
4
Enter mile to convert into meter:
0.00248548477
After converting meter to mile: 0.002485484
After converting mile to meter: 3.9999900597518

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

Approach:

• Take input of miles and meters value.
• Then call a method by passing meter and mile value as parameter.
• Inside method by using formula convert miles to meter and vice versa.
• Print the 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 input of meter value
System.out.println("Enter meter to convert into mile: ");
double meterValue=sc.nextDouble();
//taking input if mile value
System.out.println("Enter mile to convert into meter: ");
double mileValue=sc.nextDouble();
//calling user defined method convert()
convert(meterValue, mileValue);
}

public static void convert(double meterValue, double mileValue)
{
//converting meter to mile
double mile= meterValue * 0.000621371;
//converting mile to meter
double meter= mileValue * 1609.34;

//printing result
System.out.println("After converting meter to mile: "+mile);
System.out.println("After converting mile to meter: "+meter);
}
}
Output:

Enter meter to convert into mile:
4
Enter mile to convert into meter:
0.002458768
After converting meter to mile: 0.002485484
After converting mile to meter: 3.95699369312

Provided list of Simple Java Programs is specially designed for freshers and beginners to get familiarize with the concepts of Java programming language and become pro in coding.

Related Java Programs: