-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRectangle.java
55 lines (55 loc) · 968 Bytes
/
Rectangle.java
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**A Java Program to calculate the
* area and perimeter of a rectangle
* using class, object and constructors*/
import java.util.Scanner;
class Rect
{
double l,b;
Rect()
{
l=b=0.0;
}
Rect(double x,double y)
{
l=x;
b=y;
}
void input()
{
Scanner sc=new Scanner(System.in);
System.out.print("Length=");
l=sc.nextDouble();
System.out.print("Breadth=");
b=sc.nextDouble();
}
void display()
{
System.out.println("Length="+l+", Breadth="+b);
}
double area()
{
double ar;
ar=l*b;
return(ar);
}
double peri()
{
double pr;
pr=2*(l+b);
return(pr);
}
}
public class Rectangle
{
public static void main(String[] args)
{
Rect r=new Rect(3.5,2.8);
r.display();
System.out.printf("Area=%.2f\n",r.area());
System.out.println("Perimeter="+r.peri());
r.input();
r.display();
System.out.println("Area="+r.area());
System.out.println("Perimeter="+r.peri());
}
}