Java Program to Convert Foot to Yard and Yard to Foot

In the previous article, we have discussed about Java Program to Convert Foot to Mile and Mile to Foot

In this article we will see how to convert Foot to Yard and Yard to Foot by using Java programming language. Meter to feet conversion program in java Java, program to convert inches to feet, Java program to convert inches to centimeters, Java program to convert inches to feet,  Java program to convert feet and inches to centimeters, Java program to convert meters to feet, Meter to feet and feet to meter conversion java, Java program to convert feet into meters, Yard to feet convert are, you can understand by the given content below.

Java Program to Convert Foot to Yard and Yard to Foot

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

Generally Foot and Yard are used as unit in case of field length measurement.

1 Foot = 0.333333 Yard
1 Yard = 3 Foot

Formula to convert Yard to Foot.

Foot = Yard * 3

Formula to convert Foot to Yard.

Yard  = Foot * 0.333333

Let’s see different ways to convert Foot to Yard and Yard to Foot.

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

Approach:

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

Program:

public class Main 
{
   public static void main(String args[])
   {
        //value of foot declared  
        double foot = 1;
        //value of yard declared
        double yard = 1;
        
        //converting foot to yard
        double y = foot * 0.333333; 
        //converting yard to foot 
        double f = yard * 3;
        //printing result
        System.out.println("Value of "+yard+" yard in foot: "+ f);   
        System.out.println("Value of "+foot+" foot in yard: "+ y);   
   }
}
Output:

Value of 1.0 yard in foot: 3.0
Value of 1.0 foot in yard: 0.333333

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

Approach:

  • Take user input of Foot and Yard value.
  • Then convert Foot to Yard and Yard to Foot 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 yard
        System.out.println("Enter value of yard: ");  
        double yard = sc.nextDouble();
        //Taking the value input of double variable foot
        System.out.println("Enter value of foot: ");  
        double foot = sc.nextDouble();
        
        //converting foot to yard
        double y = foot * 0.333333; 
        //converting yard to foot 
        double f = yard * 3;
        //printing result
        System.out.println("Value of "+yard+" yard in foot: "+ f);   
        System.out.println("Value of "+foot+" foot in yard: "+ y);   
   }
}
Output:

Enter value of yard: 
50
Enter value of foot: 
865
Value of 50.0 yard in foot: 150.0
Value of 865.0 foot in yard: 288.33304499999997

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

Approach:

  • Take user input of Foot and Yard value.
  • Call a user defined method by passing Foot and Yard value as parameter.
  • Inside method convert Foot to Yard and Yard to Foot 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 yard
        System.out.println("Enter value of yard: ");  
        double yard = sc.nextDouble();
        //Taking the value input of double variable foot
        System.out.println("Enter value of foot: ");  
        double foot = sc.nextDouble();
         //calling user defined method convert()
        convert(yard, foot);
   }
   
   //convert() method to convert yard to foot and vice versa
   public static void convert(double yard, double foot)
   {
        //converting foot to yard
        double y = foot * 0.333333; 
        //converting yard to foot 
        double f = yard * 3;
        //printing result
        System.out.println("Value of "+yard+" yard in foot: "+ f);   
        System.out.println("Value of "+foot+" foot in yard: "+ y);   
   }
}
Output:

Enter value of yard: 
30
Enter value of foot: 
600
Value of 30.0 yard in foot: 90.0
Value of 600.0 foot in yard: 199.9998

Have you mastered basic programming topics of java and looking forward to mastering advanced topics in a java programming language? Go with these ultimate Advanced java programs examples with output & achieve your goal in improving java coding skills.

Answer yourself:

  1. Write a java program to convert feet to inches?
  2. Write an algorithm to convert feet into inches?
  3. Write a java program that reads a number in inches converts it to meters?

Related Java Programs: