-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram17.java
More file actions
37 lines (26 loc) · 925 Bytes
/
Copy pathprogram17.java
File metadata and controls
37 lines (26 loc) · 925 Bytes
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
// Create two methods:
// - One method calculates the area of a rectangle.
// - Another calculates the perimeter.
import java.util.Scanner;
class Calculator{
public int area(int l, int b){ // for calcualting area.
return l*b;
}
public int perimeter(int l, int b){
return 2*(l+b);
}
}
public class program17 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter Length : ");
int lth = sc.nextInt();
System.out.println("Enter Breadth : ");
int bth = sc.nextInt();
Calculator obj = new Calculator();
int areaRect = obj.area(lth, bth);
int periRect = obj.perimeter(lth, bth);
System.out.println("Area of Rectangle : " + areaRect);
System.out.println("Perimeter of Rectangle : " + periRect);
}
}