Simple Java Program 5: Kilometers To Meters Conversion

Now let's do a length conversion from kilometers to meters.

This program allows the user to input the value in kilometer and the program returns its value in meter.

import java.util.Scanner;
public class KmToM {

    public static void main(String[] args) {
        int m = 1000;
        System.out.println("Enter Kilometer: ");
        double km;
        Scanner reader = new Scanner(System.in);
        km = reader.nextDouble();
        double kmtometer=km*m;
        System.out.println( km+ " kilometers is " +kmtometer+ " in meters");
       
    }

}


Here's the output:


 

Comments

Post a Comment