# Java Program to Convert Nanometer to Inch and Inch to Nanometer

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

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

## Java Program to Convert Nanometer to Inch and Inch to Nanometer

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

Generally Nanometer is used to measure very small things like atoms and molecules and Inch is used for linear measurement of length.

1 Nanometer = 3.93701e-8 Inch
1 Inch = 2.54e+7 Nanometer

Formula to convert Nanometer to Inch.

Inch = Nanometer / 2.54e+7

Formula to convert Inch to Nanometer.

Nanometer = Inch * 2.54e+7

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

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

Approach:

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

//converting nanometer to inch
double in = nanometer / 2.54e+7;
//converting inch to nanometer
double nm = inch * 2.54e+7;
//printing result
System.out.println("Value of "+inch+" inch in nanometer: "+ nm);
System.out.println("Value of "+nanometer+" nanometer in inch: "+ in);
}
}
Output:

Value of 1.0 inch in nanometer: 2.54E7
Value of 1.0 nanometer in inch: 3.937007874015748E-8


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

Approach:

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

//converting nanometer to inch
double in = nanometer / 2.54e+7;
//converting inch to nanometer
double nm = inch * 2.54e+7;
//printing result
System.out.println("Value of "+inch+" inch in nanometer: "+ nm);
System.out.println("Value of "+nanometer+" nanometer in inch: "+ in);
}
}
Output:

Enter value of inch:
2
Enter value of nanometer:
200000
Value of 2.0 inch in nanometer: 5.08E7
Value of 200000.0 nanometer in inch: 0.007874015748031496


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

Approach:

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

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

Enter value of inch:
3.3
Enter value of nanometer:
80000800
Value of 3.3 inch in nanometer: 8.382E7
Value of 8.00008E7 nanometer in inch: 3.1496377952755905


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: