# Java Program to Convert Nanometer to Yard and Yard to Nanometer

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

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

## Java Program to Convert Nanometer to Yard and Yard to Nanometer

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

Generally Nanometer is used to measure very small things like atoms and molecules and Yard is used to measure distance.

1 Nanometer = 1.09361e-9 Yard
1 Yard =  9.144e+8 Nanometer

Formula to convert Nanometer to Yard.

Yard = Nanometer / 9.144e+8

Formula to convert Yard to Nanometer.

Nanometer = Yard * 9.144e+8

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

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

Approach:

• Declare Nanometer and Yard value.
• Then convert Nanometer to Yard and Yard to Nanometer 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 nanometer declared
double nanometer = 1;

//converting nanometer to yard
double y = nanometer / 9.144e+8;
//converting yard to nanometer
double nm = yard * 9.144e+8;
//printing result
System.out.println("Value of "+yard+" yard in nanometer: "+ nm);
System.out.println("Value of "+nanometer+" nanometer in yard: "+ y);
}
}
Output:

Value of 1.0 yard in nanometer: 9.144E8
Value of 1.0 nanometer in yard: 1.0936132983377077E-9


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

Approach:

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

//converting nanometer to yard
double y = nanometer / 9.144e+8;
//converting yard to nanometer
double nm = yard * 9.144e+8;
//printing result
System.out.println("Value of "+yard+" yard in nanometer: "+ nm);
System.out.println("Value of "+nanometer+" nanometer in yard: "+ y);
}
}
Output:

Enter value of yard:
5
Enter value of nanometer:
800
Value of 5.0 yard in nanometer: 4.572E9
Value of 800.0 nanometer in yard: 8.748906386701662E-7


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

Approach:

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

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

Enter value of yard:
60
Enter value of nanometer:
8000
Value of 60.0 yard in nanometer: 5.4864E10
Value of 8000.0 nanometer in yard: 8.748906386701662E-6


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: