Menu Close

Many people think about their height in feet and inches [Java]…FTC

Many people think about their height in feet and inches, even in some countries that primarily use the metric system. Write a program that reads a number of feet from the user, followed by a number of inches. Once these values are read, your program should compute and display the equivalent number of centimetres.

Hint: One foot is 12 inches. One inch is 2.54 centimetres.

Input:
Height = 5 7    // 5 Foot 7 inch 

Output:
Height in Cm = 170.18
import java.io.*;
import java.util.*;
public class temp{
  public static void main(String[] args){
    double foot,inch,cm=0;
    Scanner scan = new Scanner(System.in);
    System.out.print("Enter the Height:  ");
    foot = scan.nextDouble();
    inch = scan.nextDouble();

    foot *= 30.48;
    inch *= 2.54;
    cm = foot + inch;

    System.out.println(String.format("Your height in centimeters is %.2f",cm));
	}
}

INPUT_1:
Enter the Height:  5 7

OUTPUT:
Your height in centimeters is  170.18


INPUT_2:
Enter the Height:  6 1

OUTPUT:
Your height in centimeters is  185.42


INPUT_3:
Enter the Height:  8 2

OUTPUT:
Your height in centimeters is  248.92


INPUT_4:
Enter the Height:  6 5

OUTPUT:
Your height in centimeters is  195.58


INPUT_5:
Enter the Height:  6 2

OUTPUT:
Your height in centimeters is  187.96


ILLUSTRATION

Executed using javac in ubuntu terminal