# Java Program to Convert Hectare to Square Foot and Square Foot to Hectare

In the previous article, we have discussed about Java Program to Convert Centimeter to Meter and Meter to Centimeter

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

## Java Program to Convert Hectare to Square Foot and Square Foot to Hectare

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

Generally Hectare and Square Foot are used as unit in case of field/land length measurement.

1 Hectare = 107639 Square Foot
1 Square Foot = 9.2903e-6 Hectare

Formula to convert Hectare to Square Foot.

Square Foot = Hectare * 107639

Formula to convert Square Foot to Hectare.

Hectare  = Square Foot * 9.2903e-6

Let’s see different ways to convert Hectare to Square Foot and Square Foot to Hectare.

### Method-1: Java Program to Convert Hectare to Square Foot and Square Foot to Hectare By Using Static Input Value

Approach:

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

Program:

public class Main
{
public static void main(String args[])
{
//value of square foot declared
double squareFoot = 1;
//value of hectare declared
double hectare = 1;

//converting Hectare to Square Foot
double sf = hectare * 107639;
//converting Square Foot to Hectare
double h = squareFoot * 9.2903e-6;
//printing result
System.out.println("Value of "+hectare+" hectare in square foot: "+ sf);
System.out.println("Value of "+squareFoot+" square foot in hectare: "+ h);
}
}
Output:

Value of 1.0 hectare in square foot: 107639.0
Value of 1.0 square foot in hectare: 9.2903E-6

### Method-2: Java Program to Convert Hectare to Square Foot and Square Foot to Hectare By Using User Input Value

Approach:

• Take user input of Hectare and Square Foot value.
• Then convert Hectare to Square Foot and Square Foot to Hectare 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 squareFoot
System.out.println("Enter value of square foot: ");
double squareFoot = sc.nextDouble();
//Taking the value input of double variable hectare
System.out.println("Enter value of hectare: ");
double hectare = sc.nextDouble();

//converting Hectare to Square Foot
double sf = hectare * 107639;
//converting Square Foot to Hectare
double h = squareFoot * 9.2903e-6;
//printing result
System.out.println("Value of "+hectare+" hectare in square foot: "+ sf);
System.out.println("Value of "+squareFoot+" square foot in hectare: "+ h);
}
}
Output:

Enter value of square foot:
30000
Enter value of hectare:
5
Value of 5.0 hectare in square foot: 538195.0
Value of 30000.0 square foot in hectare: 0.278709


### Method-3: Java Program to Convert Hectare to Square Foot and Square Foot to Hectare By Using User Defined Method

Approach:

• Take user input of Hectare and Square Foot value.
• Call a user defined method by passing Hectare and Square Foot value as parameter.
• Inside method convert Hectare to Square Foot and Square Foot to Hectare 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 squareFoot
System.out.println("Enter value of square foot: ");
double squareFoot = sc.nextDouble();
//Taking the value input of double variable hectare
System.out.println("Enter value of hectare: ");
double hectare = sc.nextDouble();
//calling user defined method convert()
convert(squareFoot, hectare);
}

//convert() method to convert square foot to hectare and vice versa
public static void convert(double squareFoot, double hectare)
{

//converting Hectare to Square Foot
double sf = hectare * 107639;
//converting Square Foot to Hectare
double h = squareFoot * 9.2903e-6;
//printing result
System.out.println("Value of "+hectare+" hectare in square foot: "+ sf);
System.out.println("Value of "+squareFoot+" square foot in hectare: "+ h);
}
}
Output:

Enter value of square foot:
55555555
Enter value of hectare:
5
Value of 5.0 hectare in square foot: 538195.0
Value of 5.5555555E7 square foot in hectare: 516.1277726165


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.

Related Java Programs: