# Java Program to Convert Inch to Millimeter and Millimeter to Inch

In the previous article we have discussed about Java Program to Convert Inch to Meter and Meter to Inch

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

## Java Program to Convert Inch to Millimeter and Millimeter to Inch

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

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

1 Millimeter = 0.0393701 Inch
1 Inch  =  25.4 Millimeter

Formula to convert Inch to Millimeter.

Millimeter = Inch * 25.4

Formula to convert Millimeter to Inch.

Inch  = Millimeter / 25.4 (OR) Millimeter * 0.0393701

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

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

Approach:

• Declare Inch and Millimeter value.
• Then convert Inch to Millimeter and Millimeter to Inch 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 millimeter declared
double millimeter = 1;
// value of inch declared
double inch = 1;

//converting inch to millimeter
double mm = inch * 25.4;
//converting millimeter to inch
double in = millimeter * 0.0393701;
//printing result
System.out.println("Value of "+millimeter+" millimeter in inch: "+ in);
System.out.println("Value of "+inch+" inch in millimeter: "+ mm);
}
}
Output:

Value of 1.0 millimeter in inch: 0.03937007874015748
Value of 1.0 inch in millimeter: 25.4

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

Approach:

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

//converting inch to millimeter
double mm = inch * 25.4;
//converting millimeter to inch
double in = millimeter * 0.0393701;
//printing result
System.out.println("Value of "+millimeter+" millimeter in inch: "+ in);
System.out.println("Value of "+inch+" inch in millimeter: "+ mm);
}
}
Output:

Enter value of millimeter:
200
Enter value of inch:
25
Value of 200.0 millimeter in inch: 7.87402
Value of 25.0 inch in millimeter: 635.0


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

Approach:

• Take user input of Inch and Millimeter value.
• Call a user defined method by passing Inch and Millimeter value as parameter.
• Inside method convert Inch to Millimeter and Millimeter to Inch 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 millimeter
System.out.println("Enter value of millimeter: ");
double millimeter = sc.nextDouble();
//Taking the value input of double variable inch
System.out.println("Enter value of inch: ");
double inch = sc.nextDouble();
//calling user defined method convert()
convert(millimeter, inch);
}

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

Enter value of millimeter:
300
Enter value of inch:
30
Value of 300.0 millimeter in inch: 11.811029999999999
Value of 30.0 inch in millimeter: 762.0


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: