We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3a76b59 commit c4942a4Copy full SHA for c4942a4
src/main/java/com/thealgorithms/maths/SumOfOddNumbers.java
@@ -2,14 +2,12 @@
2
3
/**
4
* This program calculates the sum of the first n odd numbers.
5
- *
+ *
6
* https://www.cuemath.com/algebra/sum-of-odd-numbers/
7
*/
8
9
-public final class SumOfOddNumbers
10
-{
11
- private SumOfOddNumbers()
12
- {
+public final class SumOfOddNumbers {
+ private SumOfOddNumbers() {
13
}
14
15
@@ -18,10 +16,8 @@ private SumOfOddNumbers()
18
16
* @param n the number of odd numbers to sum
19
17
* @return sum of the first n odd numbers
20
21
- public static int sumOfFirstNOddNumbers(final int n)
22
23
- if (n < 0)
24
+ public static int sumOfFirstNOddNumbers(final int n) {
+ if (n < 0) {
25
throw new IllegalArgumentException("n must be non-negative.");
26
27
return n * n;
0 commit comments