# Java Program to Convert Millimeter to Yard and Yard to Millimeter

In the previous article we have discussed about Java Program to Convert Millimeter to Mile and Mile to Millimeter

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

## Java Program to Convert Millimeter to Yard and Yard to Millimeter

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

Generally Millimeter is used to measure very small length mainly we use to measure visible scale distances and Yard is used to measure length of area.

1 Millimeter = 0.00109361 Yard
1 Yard =  914.4 Millimeter

Formula to convert Millimeter to Yard.

Yard = Millimeter / 914.4

Formula to convert Yard to Millimeter.

Millimeter = Yard * 914.4

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

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

Approach:

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

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

Value of 1.0 yard in millimeter: 914.4
Value of 1.0 millimeter in yard: 0.0010936132983377078


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

Approach:

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

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

Enter value of yard:
240
Enter value of millimeter:
505050
Value of 240.0 yard in millimeter: 219456.0
Value of 505050.0 millimeter in yard: 552.3293963254594


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

Approach:

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

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

Enter value of yard:
40
Enter value of millimeter:
80000
Value of 40.0 yard in millimeter: 36576.0
Value of 80000.0 millimeter in yard: 87.48906386701663


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: