Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/main/java/com/thealgorithms/ciphers/Caesar.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public String encode(String message, int shift) {
char current = message.charAt(i); // Java law : char + int = char

if (isCapitalLatinLetter(current)) {
current += shift;
current += (char) shift;
encoded.append((char) (current > 'Z' ? current - 26 : current)); // 26 = number of latin letters
} else if (isSmallLatinLetter(current)) {
current += shift;
current += (char) shift;
encoded.append((char) (current > 'z' ? current - 26 : current)); // 26 = number of latin letters
} else {
encoded.append(current);
Expand All @@ -56,10 +56,10 @@ public String decode(String encryptedMessage, int shift) {
for (int i = 0; i < length; i++) {
char current = encryptedMessage.charAt(i);
if (isCapitalLatinLetter(current)) {
current -= shift;
current -= (char) shift;
decoded.append((char) (current < 'A' ? current + 26 : current)); // 26 = number of latin letters
} else if (isSmallLatinLetter(current)) {
current -= shift;
current -= (char) shift;
decoded.append((char) (current < 'a' ? current + 26 : current)); // 26 = number of latin letters
} else {
decoded.append(current);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/thealgorithms/maths/AliquotSum.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static int getAliquotSum(int n) {
// if n is a perfect square then its root was added twice in above loop, so subtracting root
// from sum
if (root == (int) root) {
sum -= root;
sum -= (int) root;
}
return sum;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/thealgorithms/maths/PerfectNumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static boolean isPerfectNumber2(int n) {
// if n is a perfect square then its root was added twice in above loop, so subtracting root
// from sum
if (root == (int) root) {
sum -= root;
sum -= (int) root;
}

return sum == n;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/thealgorithms/maths/Volume.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,9 @@ public static double volumePrism(double baseArea, double height) {
public static double volumePyramid(double baseArea, double height) {
return (baseArea * height) / 3;
}


public static double volumeFrustumOfCone(double r1, double r2, double height){
return (Math.PI * height / 3) * (r1 * r1 + r2 * r2 + r1 * r2);
}
}
27 changes: 27 additions & 0 deletions src/main/java/com/thealgorithms/maths/VolumeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.thealgorithms.maths;

import org.junit.Test;

import static org.junit.Assert.assertTrue;

public class VolumeTest {

@Test
public void volume(){

// test cube
assertTrue(Volume.volumeCube(7) == 343.0);
assertTrue(Volume.volumeCuboid(2, 5, 7) == 70.0);
assertTrue(Volume.volumeSphere(7) == 1436.7550402417319);
assertTrue(Volume.volumeCylinder(3, 7) == 197.92033717615698);
assertTrue(Volume.volumeHemisphere(7) == 718.3775201208659);
assertTrue(Volume.volumeCone(3, 7) == 65.97344572538566);
assertTrue(Volume.volumePrism(10, 2) == 20.0);
assertTrue(Volume.volumePyramid(10, 3) == 10.0);
assertTrue(Volume.volumeFrustumOfCone(3, 5, 7) == 359.188760060433);



}

}