Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5c7c6c4

Browse files
authored
Add volume of prism and pyramid (TheAlgorithms#2902)
1 parenta0a3922 commit5c7c6c4

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

‎src/main/java/com/thealgorithms/maths/Volume.java‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ public static void main(String[] args) {
2323

2424
/* test cone */
2525
assertDouble.compare(volumeCone(5,7),916.297857297023) ==0;
26+
27+
/*test prism*/
28+
assertDouble.compare(volumePrism(10,2),20.0) ==0;
29+
30+
/*test pyramid*/
31+
assertDouble.compare(volumePyramid(10,3),10.0) ==0;
2632

2733
}
2834

@@ -89,4 +95,26 @@ private static double volumeHemisphere(double radius) {
8995
privatestaticdoublevolumeCone(doubleradius,doubleheight) {
9096
returnMath.PI *radius *radius *height /3;
9197
}
98+
99+
/**
100+
* Calculate the volume of a prism.
101+
*
102+
* @param area of the base.
103+
* @param height of prism.
104+
* @return volume of given prism.
105+
*/
106+
privatestaticdoublevolumePrism(doublebasearea,doubleheight) {
107+
returnbasearea *height;
108+
}
109+
110+
/**
111+
* Calculate the volume of a pyramid.
112+
*
113+
* @param area of the base.
114+
* @param height of pyramid.
115+
* @return volume of given pyramid.
116+
*/
117+
privatestaticdoublevolumePyramid(doublebasearea,doubleheight) {
118+
returnbasearea *height /3;
119+
}
92120
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp