Java program to find area of rectangle using function

Let’s learn java program to find area of rectangle using function.

Java program to find area of rectangle using function

Let’s find area of rectangle in java using method or using function. Here’s java program.

import java.util.Scanner;
public class RectangleArea
{
   public static void areaRectangle(double width, double height)
   {
      double area;
      area = width * height;
      System.out.println("Area of rectangle : " + area);
   }
   public static void main(String[] args)
   {
      double width, height;
      Scanner sc = new Scanner(System.in);
      System.out.println("Please enter length of rectangle : ");
      width = sc.nextDouble();
      System.out.println("Please enter width of rectangle : ");
      height = sc.nextDouble();
      areaRectangle(width, height);
      sc.close();
   }
}


Output:

Please enter length of rectangle : 6
Please enter width of rectangle : 8
Area of rectangle = 48.0


Never stop learning. Learn java programming and how to code java.