-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPractical_23.java
More file actions
36 lines (30 loc) · 1.12 KB
/
Practical_23.java
File metadata and controls
36 lines (30 loc) · 1.12 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
/*Question := Write a program that defines a Circle class with two constructors. The first
form accepts a double value that represents the radius of the circle. The
second form accepts the integer radius of the circle and calculates the area
of the circle. */
import java.util.Scanner;
public class Practical_23 {
Double Area;
Practical_23(double radius) {
Area = (Double) (3.14 * radius * radius);
}
Practical_23(int radius) {
Area = (Double) (3.14 * radius * radius);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter Radius in Double := ");
double r1 = sc.nextDouble();
Practical_23 p1 = new Practical_23(r1);
Practical_23 p2 = new Practical_23((int)r1);
System.out.println("Area of the circle is := " + p1.Area);
System.out.println("Area of the circle is := " + p2.Area);
}
}
/*
Output :=
Enter Radius in Double :=
23.66
Area of the circle is := 1757.758184
Area of the circle is := 1661.06
*/