11 . The distance between two cities (in km is input through the keyboard.
write a program to convert and print this distance in meter ,feet inches
and centimeter.
package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// write your code here
System.out.print("Enter distance between two cities : ");
Scanner sc = new Scanner(System.in); //sc is scanner name
double distance,meter,feet,inches,centimetres; //variable is declared
distance =sc.nextDouble(); //taking input from user (in km)
meter=distance*1000;//1km = 1000m
feet=distance*3280.8399; //1km = 3280.8399;
inches=distance*39370.0787; //1km = 39370.0787;
centimetres=distance*100000; //1km = 100000;
System.out.println(distance +" kilometer = "+ meter +" meter");
System.out.println(distance +" kilometer = "+ feet +" feet");
System.out.println(distance +" kilometer = "+ inches +" inches");
System.out.println(distance +" kilometer = "+ centimetres +" Centimeters");
}
}
output:-
Enter distance between two cities : 5
5.0 kilometer = 5000.0 meter
5.0 kilometer = 16404.1995 feet
5.0 kilometer = 196850.3935 inches
5.0 kilometer = 500000.0 Centimeters
Process finished with exit code 0
Comments
Post a Comment