* Added arithmetic series

* Fixed compare two double
* Fiexed documentation
This commit is contained in:
shellhub
2020-09-13 12:16:19 +08:00
parent ddd98a9a4c
commit 4ab05480e2
3 changed files with 65 additions and 29 deletions

View File

@ -2,10 +2,10 @@ package Maths;
public class PowRecursion {
public static void main(String[] args) {
assert pow(2, 0) == Math.pow(2, 0);
assert pow(0, 2) == Math.pow(0, 2);
assert pow(2, 10) == Math.pow(2, 10);
assert pow(10, 2) == Math.pow(10, 2);
assert Double.compare(pow(2, 0), Math.pow(2, 0)) == 0;
assert Double.compare(pow(0, 2), Math.pow(0, 2)) == 0;
assert Double.compare(pow(2, 10), Math.pow(2, 10)) == 0;
assert Double.compare(pow(10, 2), Math.pow(10, 2)) == 0;
}
/**
@ -17,10 +17,6 @@ public class PowRecursion {
* @return the value {@code a}<sup>{@code b}</sup>.
*/
public static long pow(int a, int b) {
if (b == 0) {
return 1;
} else {
return a * pow(a, b - 1);
}
return b == 0 ? 1 : a * pow(a, b - 1);
}
}
}