Using Java, given 2 numbers which are the measurement of a distance in feet and inches, for example 3 feet 7 inches. Change the measurement to meters and centimeters, and display message “? feet ? inches = ? meters and ? centimeters”. The ? should be replaced by real numbers. (1 inch = 2.54 centimeter, 1 foot = 12 inches)
import java.util.Scanner; public class FeetInchesToMeters { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter number of feet: "); int feet = in.nextInt(); System.out.print("Enter number of inches: "); int inches = in.nextInt(); int totalInches = 12 * feet + inches; double totalCM = 2.54 * totalInches; int meters = (int) (totalCM / 100); double remainingCM = totalCM - (meters * 100); System.out.println(feet + " feet " + inches + " inches = " + meters + " meters and " + remainingCM + " centimeters"); } }
Get Answers For Free
Most questions answered within 1 hours.