179.5 cm in feet – Java Program to Convert Centimeters to Feet and Inches

179.5 cm in feet: In the previous article, we have seen Java Program to Find Total Notes in a Given Amount

In this article we are going to see how convert centimeters to feet and inches using Java programming language.

Java Program to Convert Centimeters to Feet and Inches

1.64 cm to feet: To convert the values from one unit to another, we must the relationship among them.

1feet = 30.48cm 

1 inch = 2.54cm

Let’s see different ways to convert centimeters to feet and inches.

Method-1: Java Program to Convert Centimeters to Feet and Inches By Using Static Input Value

Approach:

  • Initialize the values for feet and inches.
  • Calculate the values.
  • Print the result.

Program:

public class Main 
{
    public static void main(String args[])
    {
        int cm = 50;
        double inch = 0.3937 * cm;
        double feet = 0.0328 * cm;
        System.out.printf("Inches is: %.2f \n", inch);
        System.out.printf("Feet is: %.2f", feet);

    }
}
Output:

Inches is: 19.69 
Feet is: 1.64

Method-2: Java Program to Convert Centimeters to Feet and Inches By Using User Input Value and User Defined Method

Approach:

  • Take use input for values in feet and inches.
  • Then call user defined method convert()
  • Then inside method calculate the values.
  • Print the result.

Program:

import java.util.Scanner;

class Main 
{

    // Function to perform conversion
    public static void convert(int cm) 
    {
        double inch = 0.3937 * cm;
        double feet = 0.0328 * cm;
        System.out.printf("Inches is: %.2f \n", inch);
        System.out.printf("Feet is: %.2f", feet);
    }

    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter the value in centimeters: ");
        int cm = sc.nextInt();
        convert(cm);
    }
}
Output:

Enter the value in centimeters: 50
Inches is: 19.69 
Feet is: 1.64

Enhancing programming skills is very important no matter what language you have chosen. So, practice frequently with these simple java programs examples and excel in coding the complex logic.

Practice yourself:

  1. Write a java program to convert feet to inches
  2. Write a program with which you can convert a human height given in feet and inches to centimeters
  3. C program to convert centimeters to feet and inches
  4. Create a program that will convert the length in feet to centimeter
  5. Cm to feet and inches converter
  6. C program to convert inches to centimeters
  7. Python program to convert cm to feet and inches
  8. Java program to convert centimeters to inches

Related Java Programs: