-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectanglesingle.java
More file actions
32 lines (32 loc) · 894 Bytes
/
Rectanglesingle.java
File metadata and controls
32 lines (32 loc) · 894 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
import java.util.Scanner;
public class Rectanglesingle {
int breadth;
int length;
public Rectanglesingle()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the breadth : ");
breadth =sc.nextInt();
System.out.println("Enter the length : ");
length =sc.nextInt();
}
public Rectanglesingle(int breadth, int length) {
this.breadth = breadth;
this.length = length;
}
public int area() {
return length * breadth;
}
public int perimeter() {
return 2 * length + 2 * breadth;
}
public String toString() {
return "breadth= " + breadth + ",length = " + length;
}
public static void main(String[] args) {
Rectanglesingle r1 = new Rectanglesingle();
System.out.println(r1);
System.out.println(r1.area());
System.out.println(r1.perimeter());
}
}