# Java Program to Convert Foot to Inch and Inch to Foot

In the previous article, we have discussed about Java Program to Convert Hectare to Square Kilometer and Square Kilometer to Hectare

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

## Java Program to Convert Foot to Inch and Inch to Foot

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

Generally Foot and Inch are used as unit in case of length measurement.

1 Foot = 12 Inch
1 Inch = 0.0833333 Foot

Formula to convert Inch to Foot.

Foot = Inch * 0.0833333 OR Inch * 1/12

Formula to convert Foot to Inch.

Inch  = Foot * 12

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

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

Approach:

• Declare Foot and Inch value.
• Then convert Foot to Inch and Inch to Foot by using the formula.
• Print result.

Program:

public class Main
{
public static void main(String args[])
{
//value of foot declared
double foot = 1;
//value of inch declared
double inch = 1;

//converting foot to inch
double in = foot * 12;
//converting inch to foot
double f = inch * 0.0833333;
//printing result
System.out.println("Value of "+inch+" inch in foot: "+ f);
System.out.println("Value of "+foot+" foot in inch: "+ in);
}
}
Output:

Value of 1.0 inch in foot: 0.0833333
Value of 1.0 foot in inch: 12.0

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

Approach:

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

//converting foot to inch
double in = foot * 12;
//converting inch to foot
double f = inch * 0.0833333;
//printing result
System.out.println("Value of "+inch+" inch in foot: "+ f);
System.out.println("Value of "+foot+" foot in inch: "+ in);
}
}
Output:

Enter value of inch:
27
Enter value of foot:
3.5
Value of 27.0 inch in foot: 2.2499991
Value of 3.5 foot in inch: 42.0


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

Approach:

• Take user input of Foot and Inch value.
• Call a user defined method by passing Foot and Inch value as parameter.
• Inside method convert Foot to Inch and Inch 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 inch
System.out.println("Enter value of inch: ");
double inch = 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(inch, foot);
}

//convert() method to convert inch to foot and vice versa
public static void convert(double inch, double foot)
{
//converting foot to inch
double in = foot * 12;
//converting inch to foot
double f = inch * 1/12;
//printing result
System.out.println("Value of "+inch+" inch in foot: "+ f);
System.out.println("Value of "+foot+" foot in inch: "+ in);
}
}
Output:

Enter value of inch:
12
Enter value of foot:
2
Value of 12.0 inch in foot: 1.0
Value of 2.0 foot in inch: 24.0


Are you new to the java programming language? We recommend you to ace up your practice session with these Basic Java Programs Examples.

Related Java Programs: