-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path5.java
More file actions
41 lines (41 loc) · 897 Bytes
/
5.java
File metadata and controls
41 lines (41 loc) · 897 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
38
39
40
41
import java.util.*;
class Rectangle{
float length;
float breadth;
Rectangle()
{
length=0;
breadth=0;
}
Rectangle(float l,float b)
{
length=l;
breadth=b;
}
Rectangle(float l)
{
length=l;
breadth=l;
}
public float area()
{
return length*breadth;
}
}
public class Main{
public static void main(String[] args)
{
Scanner sc = new Scanner (System.in);
Rectangle ob = new Rectangle();
System.out.println("The area of rectangle is "+ob.area());
System.out.println("Enter the length and breadth");
float l= sc.nextFloat();
float b= sc.nextFloat();
Rectangle ob1 = new Rectangle(l,b);
System.out.println("The area of rectangle is "+ob1.area());
System.out.println("Enter the side of Square");
float s= sc.nextFloat();
Rectangle ob2 = new Rectangle(s);
System.out.println("The area of square is "+ob2.area());
}
}