The distance between two cities (in km.) is input through the keyboard. Write a program to convert and print this distance in meters, feet, inches and centimeters.
Overall, this program is a basic example of how Java can be used to perform simple unit conversions and input/output operations.
import java.util.Scanner; class Distance { public static void main(String arga[]) { float m,km,cm,i,ft; Scanner input = new Scanner(System.in); System.out.println("Enter the Kilometer :"); km = input.nextFloat(); m = km*1000; cm = m*100; i = cm/2.54f; ft = i/12; System.out.println("Kilometer : "+km); System.out.println("Meters : "+m); System.out.println("Centimeters : "+cm); System.out.println("Inches : "+i); System.out.println("Feet : "+ft); } }
Enter the Kilometer : 23.4 Kilometer : 23.4 Meters : 23400.0 Centimeters : 2340000.0 Inches : 921259.9 Feet : 76771.66
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions