Skip to content

Commit e897a93

Browse files
authored
Fix formatting of NthUglyNumber (TheAlgorithms#4248)
1 parent 1afc4cc commit e897a93

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/main/java/com/thealgorithms/maths/NthUglyNumber.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.thealgorithms.maths;
22

3-
import java.lang.IllegalArgumentException;
43
import java.util.ArrayList;
54
import java.util.Arrays;
65
import java.util.HashMap;
@@ -16,16 +15,16 @@
1615
* - the base [2, 3, 5] ugly numbers are the same as base [5, 6, 2, 3, 5] ugly numbers
1716
*/
1817
public class NthUglyNumber {
19-
ArrayList<Long> uglyNumbers = new ArrayList<>(Arrays.asList(1L));
20-
final int[] baseNumbers;
21-
HashMap<Integer, Integer> positions = new HashMap<>();
18+
private ArrayList<Long> uglyNumbers = new ArrayList<>(Arrays.asList(1L));
19+
private final int[] baseNumbers;
20+
private HashMap<Integer, Integer> positions = new HashMap<>();
2221

2322
/**
2423
* @brief initialized the object allowing to compute ugly numbers with given base
2524
* @param baseNumbers the given base of ugly numbers
2625
* @exception IllegalArgumentException baseNumber is empty
2726
*/
28-
NthUglyNumber(int[] baseNumbers) {
27+
NthUglyNumber(final int[] baseNumbers) {
2928
if (baseNumbers.length == 0) {
3029
throw new IllegalArgumentException("baseNumbers must be non-empty.");
3130
}
@@ -41,7 +40,7 @@ public class NthUglyNumber {
4140
* @exception IllegalArgumentException n is negative
4241
* @return the n-th ugly number (starting from index 0)
4342
*/
44-
public Long get(int n) {
43+
public Long get(final int n) {
4544
if (n < 0) {
4645
throw new IllegalArgumentException("n must be non-negative.");
4746
}
@@ -67,7 +66,7 @@ private void updatePositions() {
6766
}
6867
}
6968

70-
private long computeCandidate(int candidateBase) {
69+
private long computeCandidate(final int candidateBase) {
7170
return candidateBase * uglyNumbers.get(positions.get(candidateBase));
7271
}
7372

0 commit comments

Comments
 (0)