Java Program to Convert Cubic Inch to Cubic Foot and Cubic Foot to Cubic Inch

In this article we will see how to convert Cubic Inch to Cubic Foot and Cubic Foot to Cubic Inch by using Java programming language.

Java Program to Convert Cubic Inch to Cubic Foot and Cubic Foot to Cubic Inch

Before jumping into the program let’s know the relationship between Cubic Inch and Cubic Foot and how we can convert Cubic Inch to Cubic Foot and vice versa.

Both Cubic Inch and Cubic Foot are used as unit of measuring volume of three dimensional object when length, width and height are given

1 Cubic Foot =  1728 Cubic Inch
1 Cubic Inch  = 0.000578704 Cubic Foot

Formula to convert Cubic Inch to Cubic Foot.

Cubic Foot = Cubic Inch / 1728

Formula to convert Cubic Foot  to Cubic Inch.

Cubic Inch  = Cubic Foot * 1728

Let’s see different ways to convert Cubic Inch to Cubic Foot and Cubic Foot to Cubic Inch.

Method-1: Java Program to Convert Cubic Inch to Cubic Foot and Cubic Foot to Cubic Inch By Using Static Input Value

Approach:

  • Declare Cubic Inch and Cubic Foot value.
  • Then convert Cubic Inch to Cubic Foot and Cubic Foot to Cubic Inch by using the formula.
  • Print result.

Program:

import java.util.*;
public class Main 
{
   public static void main(String args[])
   {
        //Scanner class object created
        Scanner sc=new Scanner(System.in);
        //value of cubic inch declared
        double cubicInch = 1;
        //value of cubic foot declared  
        double cubicFoot = 1;

        //converting cubic inch to cubic foot
        double cf = cubicInch / 1728 ;
        //converting cubic foot to cubic inch 
        double ci = cubicFoot * 1728;
        //printing result
        System.out.println("Value of "+cubicInch+" cubic inch in cubic foot: "+ cf);   
        System.out.println("Value of "+cubicFoot+" cubic foot in cubic inch: "+ ci);   
   }
}
Output:

Value of 1.0 cubic inch in cubic foot: 5.787037037037037E-4
Value of 1.0 cubic foot in cubic inch: 1728.0

Method-2: Java Program to Convert Cubic Inch to Cubic Foot and Cubic Foot to Cubic Inch By Using User Input Value

Approach:

  • Take user input of Cubic Inch and Cubic Foot value.
  • Then convert Cubic Inch to Cubic Foot and Cubic Foot to Cubic Inch by using the formula.
  • Print result.

Program:

import java.util.*;
public class Main 
{
   public static void main(String args[])
   {
        //Scanner class object created
        Scanner sc=new Scanner(System.in);
        //Taking the value input of double variable cubicInch
        System.out.println("Enter value of cubic inch: ");  
        double cubicInch = sc.nextDouble();
        //Taking the value input of double variable cubicFoot
        System.out.println("Enter value of cubic foot: ");  
        double cubicFoot = sc.nextDouble();

        //converting cubic inch to cubic foot
        double cf = cubicInch / 1728 ;
        //converting cubic foot to cubic inch 
        double ci = cubicFoot * 1728;
        //printing result
        System.out.println("Value of "+cubicInch+" cubic inch in cubic foot: "+ cf);   
        System.out.println("Value of "+cubicFoot+" cubic foot in cubic inch: "+ ci);   
   }
}
Output:

Enter value of cubic inch: 
100000
Enter value of cubic foot: 
2
Value of 100000.0 cubic inch in cubic foot: 57.870370370370374
Value of 2.0 cubic foot in cubic inch: 3456.0

Method-3: Java Program to Convert Cubic Inch to Cubic Foot and Cubic Foot to Cubic Inch By Using User Defined Method

Approach:

  • Take user input of Cubic Inch and Cubic Foot value.
  • Call a user defined method by passing Cubic Inch and Cubic Foot value as parameter.
  • Inside method convert Cubic Inch to Cubic Foot and Cubic Foot to Cubic Inch by using the formula.
  • Print result.

Program:

import java.util.*;
public class Main 
{
   public static void main(String args[])
   {
        //Scanner class object created
        Scanner sc=new Scanner(System.in);
        //Taking the value input of double variable cubicInch
        System.out.println("Enter value of cubic inch: ");  
        double cubicInch = sc.nextDouble();
        //Taking the value input of double variable cubicFoot
        System.out.println("Enter value of cubic foot: ");  
        double cubicFoot = sc.nextDouble();
         //calling user defined method convert()
        convert(cubicInch, cubicFoot);
   }
   
   
   //convert() method to convert cubic inch to cubic foot and vice versa
   public static void convert(double cubicInch, double cubicFoot)
   {
        //converting cubic inch to cubic foot
        double cf = cubicInch / 1728 ;
        //converting cubic foot to cubic inch 
        double ci = cubicFoot * 1728;
        //printing result
        System.out.println("Value of "+cubicInch+" cubic inch in cubic foot: "+ cf);   
        System.out.println("Value of "+cubicFoot+" cubic foot in cubic inch: "+ ci);   
   }
}
Output:

Enter value of cubic inch: 
564321
Enter value of cubic foot: 
234
Value of 564321.0 cubic inch in cubic foot: 326.57465277777777
Value of 234.0 cubic foot in cubic inch: 404352.0

The best and excellent way to learn a java programming language is by practicing Simple Java Program Examples as it includes basic to advanced levels of concepts.

Related Java Programs: