Computer Science, asked by abinshajiabin2006, 4 months ago

JAVA PROGRAM
write a java program to calculate the perimeter and area of square and rectangle using two separate functions


note: whoever says the correct code will be rewarded +200 points

Answers

Answered by Answers9999999
0

Answer:

Program 1:

User would provide the length and width values during execution of the program and the area would be calculated based on the provided values.

/**

* @author: BeginnersBook.com

* @description: Program to Calculate Area of rectangle

*/

import java.util.Scanner;

class AreaOfRectangle {

  public static void main (String[] args)

  {

   Scanner scanner = new Scanner(System.in);

   System.out.println("Enter the length of Rectangle:");

   double length = scanner.nextDouble();

   System.out.println("Enter the width of Rectangle:");

   double width = scanner.nextDouble();

   //Area = length*width;

   double area = length*width;

   System.out.println("Area of Rectangle is:"+area);

  }

}

Output:

Enter the length of Rectangle:

2

Enter the width of Rectangle:

8

Area of Rectangle is:16.0

Program 2:

In the above program, user would be asked to provide the length and width values. If you do not need user interaction and simply want to specify the values in program, refer the below program.

/**

* @author: BeginnersBook.com

* @description: Calculation with no user interaction

*/

class AreaOfRectangle2 {

  public static void main (String[] args)

  {

   double length = 4.5;

   double width = 8.0;

   double area = length*width;

   System.out.println("Area of Rectangle is:"+area);

  }

}

Output:

Area of Rectangle is:36.0

and pls don't ever lie

Similar questions