Java Program to Kilo Meters to Meters

Get Kilometer km from user and find meter m

Sample Input 1:

56

Sample Output 1:

56000

Try your Solution

Strongly recommended to Solve it on your own, Don't directly go to the solution given below.

public class Hello { public static void main(String args[]) { //Write your code here } }

Program or Solution

				
			
					
import java.util.*;
class KmToMts
{
     public static void main(String args[])
     {
          float km,metres;
          Scanner sc=new Scanner(System.in);
          System.out.println("Enter The Kilo Meters:");
          km=sc.nextFloat();
          metres=km*1000;
          System.out.printf("The Output 1 Is:\n%.0f",metres);
      }
}
			
				
			

Program Explanation

Get kilometer km as input (using scanner class) (since kilometer may be in fractional values like 1 and 5, it is declared & read as integer.)

Calculate meter m by multiplying kilometer km with 1000.

(m=km*1000, 1000 meter is equal to 1 kilometer) print meter m. (using system.out.println)

Comments