Nanometer to milimeter: In the previous article we have discussed about Java Program to Convert Millimeter to Micrometer and Micrometer to Millimeter
In this article we will see how to convert Millimeter to Nanometer and Nanometer to Millimeter by using Java programming language.
Java Program to Convert Millimeter to Nanometer and Nanometer to Millimeter
Nanometer in millimeter: Before jumping into the program let’s know the relationship between Millimeter and Nanometer.
Generally Millimeter is used to measure very small length mainly we use to measure visible scale distances and Nanometer is used to measure very very small things like atoms and molecules.
1 Millimeter = 1000000 Nanometer 1 Nanometer = 1e-6 Millimeter
Formula to convert Millimeter to Nanometer.
Nanometer = Millimeter * 1e+6
Formula to convert Nanometer to Millimeter.
Millimeter = Nanometer / 1e+6
Let’s see different ways to convert Millimeter to Nanometer and Nanometer to Millimeter.
Method-1: Java Program to Convert Millimeter to Nanometer and Nanometer to Millimeter By Using Static Input Value
Approach:
- Declare Millimeter and Nanometer value.
- Then convert Millimeter to Nanometer and Nanometer 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 nanometer declared double nanometer = 1; //value of millimeter declared double millimeter = 1; //converting millimeter to nanometer double nm = millimeter * 1e+6; //converting nanometer to millimeter double mm = nanometer / 1e+6; //printing result System.out.println("Value of "+nanometer+" nanometer in millimeter: "+ mm); System.out.println("Value of "+millimeter+" millimeter in nanometer: "+ nm); } }
Output: Value of 1.0 nanometer in millimeter: 1.0E-6 Value of 1.0 millimeter in nanometer: 1000000.0
Method-2: Java Program to Convert Millimeter to Nanometer and Nanometer to Millimeter By Using User Input Value
Approach:
- Take user input of Millimeter and Nanometer value.
- Then convert Millimeter to Nanometer and Nanometer 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 nanometer System.out.println("Enter value of nanometerr: "); double nanometer = sc.nextDouble(); //Taking the value input of double variable millimeter System.out.println("Enter value of millimeter: "); double millimeter = sc.nextDouble(); //converting millimeter to nanometer double nm = millimeter * 1e+6; //converting nanometer to millimeter double mm = nanometer / 1e+6; //printing result System.out.println("Value of "+nanometer+" nanometer in millimeter: "+ mm); System.out.println("Value of "+millimeter+" millimeter in nanometer: "+ nm); } }
Output: Enter value of nanometerr: 5000000 Enter value of millimeter: 5 Value of 5000000.0 nanometer in millimeter: 5.0 Value of 5.0 millimeter in nanometer: 5000000.0
Method-3: Java Program to Convert Millimeter to Nanometer and Nanometer to Millimeter By Using User Defined Method
Approach:
- Take user input of Millimeter and Nanometer value.
- Call a user defined method by passing Millimeter and Nanometer value as parameter.
- Inside method convert Millimeter to Nanometer and Nanometer 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 nanometer System.out.println("Enter value of nanometerr: "); double nanometer = 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(nanometer, millimeter); } //convert() method to convert nanometer to millimeter and vice versa public static void convert(double nanometer, double millimeter) { //converting millimeter to nanometer double nm = millimeter * 1e+6; //converting nanometer to millimeter double mm = nanometer / 1e+6; //printing result System.out.println("Value of "+nanometer+" nanometer in millimeter: "+ mm); System.out.println("Value of "+millimeter+" millimeter in nanometer: "+ nm); } }
Output: Enter value of nanometerr: 60000 Enter value of millimeter: 6 Value of 60000.0 nanometer in millimeter: 0.06 Value of 6.0 millimeter in nanometer: 6000000.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: