Monday, January 13, 2025
HomeProgrammingProgram to Convert cm to Feet and Inches

Program to Convert cm to Feet and Inches

Here’s a simple Java program to convert centimeters to feet and inches:

java
import java.util.Scanner;

public class CMToFeetInches {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter length in cm: ");
double cm = scanner.nextDouble();

// Conversion
int feet = (int) (cm / 30.48); // 1 foot = 30.48 cm
double inches = (cm % 30.48) / 2.54; // 1 inch = 2.54 cm

System.out.println(cm + " cm = " + feet + " feet and " + (int)inches + " inches.");
}
}

This program reads the input in centimeters, converts it to feet (1 foot = 30.48 cm), and then calculates the remaining inches (1 inch = 2.54 cm). The result is displayed in feet and inches.

RELATED ARTICLES

Python Lambda Functions

What Are Data Types In Java

0 0 votes
Article Rating

Leave a Reply

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
- Advertisment -

Most Popular

Recent Comments

0
Would love your thoughts, please comment.x
()
x