-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask12.java
More file actions
45 lines (44 loc) · 1.19 KB
/
Task12.java
File metadata and controls
45 lines (44 loc) · 1.19 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
41
42
43
44
45
/*
Develop a class named Rectangle with private data members length and width. Make a parameterized Constructor to initialize data members. Now make two methods rectarea() and rectperi() to calculate area and perimeter. Test the class Rectangle.
*/
import java.util.*;
class Rectangle
{
private long length,area;
private long width,peri;
Rectangle(long l,long w)
{
length=l;
width=w;
}
public long Area(long a,long b)
{
area=a*b;
return area;
}
public long Perimeter(long a,long b)
{
peri=2*(a+b);
return peri;
}
public void Display()
{
System.out.println("Area : "+area);
System.out.print("Perimeter : "+peri);
}
}
class Task
{
public static void main(String... args)
{
long l1,w1;
Scanner sc = new Scanner(System.in);
System.out.print("Enter the length of rectangle=");
l1=sc.nextLong();
System.out.print("Enter the width of rectangle=");
w1=sc.nextLong();
Rectangle d = new Rectangle(l1,w1);
System.out.println("Area Of Rectangle="+d.Area(l1,w1));
System.out.println("Perimeter Of Rectangle="+d.Perimeter(l1,w1));
}
}