forked from chetannihith/Java-hacktoberfest25
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrintAreaOfShape.java
More file actions
40 lines (32 loc) · 1.37 KB
/
PrintAreaOfShape.java
File metadata and controls
40 lines (32 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package hacktoberfest;
import java.util.Scanner;
public class PrintAreaOfShape {
// Method to print the area of a square
public static void printAreaOfSquare(double side) {
double area = side * side;
System.out.println("Area of square of side " + side + " units is = " + area + " sq. units.");
}
// Method to print the area of a rectangle
public static void printAreaOfRectangle(double length, double breadth) {
double area = length * breadth;
System.out.println("Area of rectangle of length " + length + " units and breadth "
+ breadth + " units is = " + area + " sq. units.");
}
// Driver code
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// User input for side of square
System.out.print("Enter the side of the square = ");
double sqSide = sc.nextDouble();
printAreaOfSquare(sqSide);
System.out.println();
// User input for length and breadth of rectangle
System.out.print("Enter the length of the rectangle = ");
double rectLength = sc.nextDouble();
System.out.print("Enter the breadth of the rectangle = ");
double rectBreadth = sc.nextDouble();
printAreaOfRectangle(rectLength, rectBreadth);
// close the scanner
sc.close();
}
}