-
Notifications
You must be signed in to change notification settings - Fork 2
/
Q10_Overload_Area_fun.java
32 lines (30 loc) · 1.17 KB
/
Q10_Overload_Area_fun.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
//Q10. WAP to show the overloading of area function.
package JAVA_Lab_File;
import java.util.Scanner;
public class Q10_Overload_Area_fun {
static void area(double radius){
double area = Math.PI * radius * radius;
System.out.print("Area of Circle is: " + String.format("%.5f", area) + " sq. units");
}
static void area(double base, double height){
double area = 0.5*base*height;
System.out.print("Area of Triangle is: " + String.format("%.5f", area) + " sq. units");
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Calculate Area: \n1.Circle\n2.Triangle\nChoice: ");
int choice = sc.nextInt();
if(choice == 1){
System.out.print("Enter the radius of the circle: ");
double radius = sc.nextDouble();
area(radius);
} else if (choice == 2) {
System.out.print("Enter the base and height of the triangle: ");
double base = sc.nextDouble();
double height = sc.nextDouble();
area(base, height);
}else {
System.out.println("Invalid choice");
}
}
}