17. JAVA Program to convert Kilometers into Meters and Centimeters.
How does this program work?
- The distance between Two cities is given by the user is stored in a variable.
- By using the formula we can get the distance in meters and centimeters.
- The output of the given question is here solved by using java .
Here is the code
// To Convert kilometer into meters and centimeters
import java.util.Scanner;public class Distance
{
public static void main(String args[])
{
int a,b,c;
System.out.println("Enter the distance between two cities in kilometers\n");
Scanner obj1=new Scanner(System.in);
a=obj1.nextInt();
// Convert kilometers into meters
b=a*1000;// Convert kilometers into centimeters
c=a*100000;System.out.println("Distance between the two cities is "+b+ " meters\n");
System.out.println("Distance between the two cities is "+c+ " centimeters\n");
}
}