In the previous article, we have discussed about Java Program to Convert Hectare to Square Mile and Square Mile to Hectare
In this article we will see how to convert Hectare to Square Yard and Square Yard to Hectare by using Java programming language.
Java Program to Convert Hectare to Square Yard and Square Yard to Hectare
Before jumping into the program let’s know the relationship between Hectare and Square Yard and how we can convert Hectare to Square Yard and vice versa.
Generally Hectare and Square Yard are used as unit in case of field/plot/land measurement.
1 Hectare = 11960 Square Yard 1 Square Yard = 8.3613e-5 Hectare
Formula to convert Hectare to Square Yard.
Square Yard = Hectare * 11960
Formula to convert Square Yard to Hectare.
Hectare = Square Yard * 8.3613e-5 (OR) Square Yard / 11960
Let’s see different ways to convert Hectare to Square Yard and Square Yard to Hectare.
Method-1: Java Program to Convert Hectare to Square Yard and Square Yard to Hectare By Using Static Input Value
Approach:
- Declare Hectare and Square Yard value.
- Then convert Hectare to Square Yard and Square Yard 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); //value of square yard declared double squareyard = 1; //value of hectare declared double hectare = 1; //converting Hectare to square yard double sy = hectare * 11960; //converting square yard to Hectare double h = squareyard / 11960; //printing result System.out.println("Value of "+hectare+" hectare in square yard: "+ sy); System.out.println("Value of "+squareyard+" square yard in hectare: "+ h); } }
Output: Value of 1.0 hectare in square yard: 11960.0 Value of 1.0 square yard in hectare: 8.361204013377926E-5
Method-2: Java Program to Convert Hectare to Square Yard and Square Yard to Hectare By Using User Input Value
Approach:
- Take user input of Hectare and Square Yard value.
- Then convert Hectare to Square Yard and Square Yard 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 squareyard System.out.println("Enter value of square yard: "); double squareyard = 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 yard double sy = hectare * 11960; //converting square yard to Hectare double h = squareyard / 11960; //printing result System.out.println("Value of "+hectare+" hectare in square yard: "+ sy); System.out.println("Value of "+squareyard+" square yard in hectare: "+ h); } }
Output: Enter value of square yard: 50 Enter value of hectare: 5 Value of 5.0 hectare in square yard: 59800.0 Value of 50.0 square yard in hectare: 0.004180602006688963
Method-3: Java Program to Convert Hectare to Square Yard and Square Yard to Hectare By Using User Defined Method
Approach:
- Take user input of Hectare and Square Yard value.
- Call a user defined method by passing Hectare and Square Yard value as parameter.
- Inside method convert Hectare to Square Yard and Square Yard 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 squareyard System.out.println("Enter value of square yard: "); double squareyard = 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(squareyard, hectare); } //convert() method to convert square yard to hectare and vice versa public static void convert(double squareyard, double hectare) { //converting Hectare to square yard double sy = hectare * 11960; //converting square yard to Hectare double h = squareyard * 8.3613e-5; //printing result System.out.println("Value of "+hectare+" hectare in square yard: "+ sy); System.out.println("Value of "+squareyard+" square yard in hectare: "+ h); } }
Output: Enter value of square yard: 50 Enter value of hectare: 5 Value of 5.0 hectare in square yard: 59800.0 Value of 50.0 square yard in hectare: 0.00418065
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: