forked from IamBisrutPyne/Java-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvolumeFunctionOverloading.java
More file actions
40 lines (30 loc) · 1.14 KB
/
volumeFunctionOverloading.java
File metadata and controls
40 lines (30 loc) · 1.14 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
import java.util.*;
public class volumeFunctionOverloading {
public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
System.out.print("Enter radius of sphere: ");
int r = sc.nextInt();
System.out.print("Enter side of cube: ");
float s = sc.nextFloat();
System.out.print("Enter length, breadth, and height of cuboid: ");
int l = sc.nextInt();
int b = sc.nextInt();
int h = sc.nextInt();
calculate(r);
calculate(s);
calculate(l, b, h);
}
}
static void calculate(int radius) {
double volume = (4.0 / 3.0) * Math.PI * Math.pow(radius, 3);
System.out.printf("The Volume of Sphere = %.2f%n", volume);
}
static void calculate(float side) {
double volume = Math.pow(side, 3);
System.out.printf("The Volume of Cube = %.2f%n", volume);
}
static void calculate(int length, int breadth, int height) {
double volume = length * breadth * height;
System.out.printf("The Volume of Cuboid = %.2f%n", volume);
}
}