Java Program to Convert Acer to Hectare and Hectare to Acer

In the previous article, we have discussed about Java Program to Calculate Remaining Loan Amount to Pay Back

In this article we will see how to convert acer to hectare and hectare to acer by using Java programming language.

Java Program to Convert Acer to Hectare and Hectare to Acer

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

1 Acer = 0.404686 Hectare
1 Hectare = 2.47105 Acer

Formula to convert acer to hectare.

Hectare = Acer * 0.404686

Formula to convert hectare to acer .

Acer = Hectare* 2.47105

Let’s see different ways to find convert acer to hectare and vice versa.

Method-1: Java Program to Convert Acer to Hectare and Hectare to Acer By Using Static Input Value

Approach:

  • Declare user input of acerĀ  and hectare value.
  • Then convert acer to hectare and hectare to acer by using the formula.
  • Print result.

Program:

public class Main 
{
   public static void main(String args[])
   {
        //value of acer declared
        double acer = 1;
        //value of hectare declared  
        double hectare = 1;
        
        //calculating acer value
        double a  = hectare * 2.47105; 
        //calculating hectare value
        double h = acer * 0.404686;
        //printing result
        System.out.println("Value in acer is: "+ a);   
        System.out.println("Value in hectare is: "+ h);   
   }
}
Output:

Value in acer is: 2.47105
Value in hectare is: 0.404686

Method-2: Java Program to Convert Acer to Hectare and Hectare to Acer By Using User Input Value

Approach:

  • Take user input of acer and hectare value.
  • Then convert acer to hectare and hectare to acer 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 acer
        System.out.println("Enter value of acer: ");  
        double acer = sc.nextDouble();
        //Taking the value input of double variable hectare
        System.out.println("Enter value of hectare: ");  
        double hectare = sc.nextDouble();
        
        //calculating acer value
        double a  = hectare * 2.47105; 
        //calculating hectare value
        double h = acer * 0.404686;
        //printing result
        System.out.println("Value in acer is: "+ a);   
        System.out.println("Value in hectare is: "+ h);   
   }
}
Output:

Enter value of acer: 
2
Enter value of hectare: 
4
Value in acer is: 9.8842
Value in hectare is: 0.809372

Method-3: Java Program to Convert Acer to Hectare and Hectare to Acer By Using User Defined Method

Approach:

  • Take user input of acer and hectare value.
  • Call a user defined method by passing acer and hectare value as parameter.
  • Inside method convert acer to hectare and vice versa 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 acer
        System.out.println("Enter value of acer: ");  
        double acer = 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(acer, hectare);
   }
   
   //convert() method to convert acer to hectare and vice versa
   public static void convert(double acer, double hectare)
   {
        
        //calculating acer value
        double a  = hectare * 2.47105; 
        //calculating hectare value
        double h = acer * 0.404686;
        //printing result
        System.out.println("Value in acer is: "+ a);   
        System.out.println("Value in hectare is: "+ h);   
   }
}
Output:

Enter value of acer: 
5
Enter value of hectare: 
5
Value in acer is: 12.35525
Value in hectare is: 2.02343

Guys who are serious about learning the concepts of the java programming language should practice this list of programs in java and get a good grip on it for better results in exams or interviews.

Related Java Programs: