Java Program to Convert Foot to Mile and Mile to Foot

In the previous article, we have discussed about Java Program to Convert Foot to Nautical Mile and Nautical Mile to Foot

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

Java Program to Convert Foot to Mile and Mile to Foot

Before jumping into the program let’s know the relationship between Foot and Mile and how we can convert Foot to Mile and vice versa.

Generally Foot and Mile are used as unit in case of length/distance measurement.

1 Foot =  0.000189394 Mile
1 Mile =  5280 Feet

Formula to convert Mile to Foot.

Foot = Mile * 5280

Formula to convert Foot to Mile.

Mile = Foot * 0.000189394

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

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

Approach:

  • Declare Foot and Nautical Mile value.
  • Then convert Foot to Nautical Mile and Nautical Mile to Foot 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 foot declared  
        double foot = 1;

        //converting foot to Mile
        double m = foot * 0.000189394; 
        //converting Mile to foot 
        double f = mile * 5280;
        //printing result
        System.out.println("Value of "+mile+" Mile in foot: "+ f);   
        System.out.println("Value of "+foot+" foot in Mile: "+ m);   
   }
}
Output:

Value of 1.0 Mile in foot: 5280.0
Value of 1.0 foot in Mile: 1.89394E-4

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

Approach:

  • Take user input of Foot and Mile value.
  • Then convert Foot to Mile and Mile to Foot 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 foot
        System.out.println("Enter value of foot: ");  
        double foot = sc.nextDouble();

        //converting foot to Mile
        double m = foot * 0.000189394; 
        //converting Mile to foot 
        double f = mile * 5280;
        //printing result
        System.out.println("Value of "+mile+" Mile in foot: "+ f);   
        System.out.println("Value of "+foot+" foot in Mile: "+ m);   
   }
}
Output:

Enter value of Mile: 
6
Enter value of foot: 
6909
Value of 6.0 Mile in foot: 31680.0
Value of 6909.0 foot in Mile: 1.308523146

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

Approach:

  • Take user input of Foot and Mile value.
  • Call a user defined method by passing Foot and Mile value as parameter.
  • Inside method convert Foot to Mile and Mile to Foot 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 foot
        System.out.println("Enter value of foot: ");  
        double foot = sc.nextDouble();
         //calling user defined method convert()
        convert(mile, foot);
   }
   
   //convert() method to convert mile to foot and vice versa
   public static void convert(double mile, double foot)
   {
        //converting foot to Mile
        double m = foot * 0.000189394; 
        //converting Mile to foot 
        double f = mile * 5280;
        //printing result
        System.out.println("Value of "+mile+" Mile in foot: "+ f);   
        System.out.println("Value of "+foot+" foot in Mile: "+ m);   
   }
}
Output:

Enter value of Mile: 
4
Enter value of foot: 
897090
Value of 4.0 Mile in foot: 21120.0
Value of 897090.0 foot in Mile: 169.90346346

Beginners and experienced programmers can rely on these Best Java Programs Examples and code various basic and complex logics in the Java programming language with ease.

Related Java Programs: