Millimeter to meter – Java Program to Convert Meter to Millimeter and Millimeter to Meter

Millimeter to meter: In the previous article we have discussed about Java Program to Convert Meter to Centimeter and Centimeter to Meter

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

Java Program to Convert Meter to Millimeter and Millimeter to Meter

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

Generally Millimeter is used to measure very small length while Meter is used to measure long length and distance between two two points.

1 Meter = 1000 Millimeter
1 Millimeter = 0.001 Meter

Formula to convert Meter to Millimeter.

Millimeter = Meter * 1000

Formula to convert Millimeter to Meter.

Meter = Millimeter / 1000

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

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

Approach:

  • Declare Meter and Millimeter value.
  • Then convert Meter to Millimeter and Millimeter to Meter 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 meter declared 
        double meter = 1;

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

Value of 1.0 millimeter in meter: 0.001
Value of 1.0 meter in millimeter: 1000.0

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

Approach:

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

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

Enter value of millimeter: 
46000
Enter value of meter: 
8
Value of 46000.0 millimeter in meter: 46.0
Value of 8.0 meter in millimeter: 8000.0

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

Approach:

  • Take user input of Meter and Millimeter value.
  • Call a user defined method by passing Meter and Millimeter value as parameter.
  • Inside method convert Meter to Millimeter and Millimeter to Meter 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 meter
        System.out.println("Enter value of meter: ");  
        double meter = sc.nextDouble();
        //calling user defined method convert()
        convert(millimeter, meter);
   }
   
   //convert() method to convert millimeter to meter and vice versa
   public static void convert(double millimeter, double meter)
   {
        //converting meter to millimeter
        double mm = meter*1000;
        //converting millimeter to meter
        double m = millimeter/1000;
        //printing result
        System.out.println("Value of "+millimeter+" millimeter in meter: "+ m);   
        System.out.println("Value of "+meter+" meter in millimeter: "+ mm);   
   }
}
Output:

Enter value of millimeter: 
6700
Enter value of meter: 
5
Value of 6700.0 millimeter in meter: 6.7
Value of 5.0 meter in millimeter: 5000.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: