-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQue-19.java
More file actions
31 lines (31 loc) · 815 Bytes
/
Copy pathQue-19.java
File metadata and controls
31 lines (31 loc) · 815 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
//Create a Class called triangle having an attribute length and breadth, it has two Methods to calculate the area and perimeter of the triangle, write a program to test the Class triangle by creating at least two triangles.
//By: Parth Panjwani
class Triangle
{
int length, breadth;
Triangle(int l, int b)
{
length = l;
breadth = b;
}
void area()
{
System.out.println("Area of triangle: "+0.5*length*breadth);
}
void perimeter()
{
System.out.println("Perimeter of triangle: "+2*(length+breadth));
}
}
class Que19
{
public static void main(String[] args)
{
Triangle t1 = new Triangle(10,20);
t1.area();
t1.perimeter();
Triangle t2 = new Triangle(20,30);
t2.area();
t2.perimeter();
}
}