# 5700 m to km – Java Program to Convert Kilometer to Meter and Meter to Kilometer

5700 m to km: In the previous article we have discussed about Java Program to Convert Inch to Yard and Yard to Inch

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

## Java Program to Convert Kilometer to Meter and Meter to Kilometer

5700 meters to kilometers: Before jumping into the program let’s know the relationship between Kilometer and Meter and how we can convert Kilometer to Meter and vice versa.

Generally Kilometer and Meter are used as unit in case of length/distance measurement.

1 Kilometer =  1000 Meter
1 Meter = 0.001 Kilometer

Formula to convert Kilometer to Meter.

Meter = Kilometer*1000

Formula to convert Meter to Kilometer.

Kilometer = Meter/1000 (OR) Meter*0.001

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

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

Approach:

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

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

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

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

Approach:

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

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

Enter value of meter:
5700
Enter value of kilometer:
4
Value of 5700.0 meter in kilometer: 5.7
Value of 4.0 kilometer in meter: 4000.0


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

Approach:

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

//convert() method to convert meter to kilometer and vice versa
public static void convert(double meter, double kilometer)
{
//converting kilometer to meter
double m = kilometer*1000;
//converting meter to kilometer
double km = meter*0.001;
//printing result
System.out.println("Value of "+meter+" meter in kilometer: "+ km);
System.out.println("Value of "+kilometer+" kilometer in meter: "+ m);
}
}
Output:

Enter value of meter:
1200
Enter value of kilometer:
3.4
Value of 1200.0 meter in kilometer: 1.2
Value of 3.4 kilometer in meter: 3400.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.

Test Yourself:

1. Write a program to convert kilometers to meters in c?
2. Write a program to convert meter into centimeter in java?
3. Write a java program to convert centimeter to inch meter and kilometer?
4. java program to convert kilometer to meter and meter to kilometer?
5. Convert meter to kilometer in java?
6. Program to convert meters into kilometers?
7. Python program to convert meter to kilometer?
8. Program to convert meters into kilometers?
9. Meter to kilometer formula?
10. Meter to kilometer chart?

Related Java Programs: