mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-22 03:24:57 +08:00
style: enable ConstantName
in checkstyle (#5139)
Co-authored-by: Maria Paszkiewicz SCC <maria.paszkiewicz@kit.edu>
This commit is contained in:
@ -9,7 +9,7 @@ import java.util.Scanner;
|
||||
*/
|
||||
public class Fibonacci {
|
||||
|
||||
private static final Map<Integer, Integer> map = new HashMap<>();
|
||||
private static final Map<Integer, Integer> CACHE = new HashMap<>();
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Methods all returning [0, 1, 1, 2, 3, 5, ...] for n = [0, 1, 2, 3, 4, 5, ...]
|
||||
@ -30,8 +30,8 @@ public class Fibonacci {
|
||||
* Outputs the nth fibonacci number
|
||||
*/
|
||||
public static int fibMemo(int n) {
|
||||
if (map.containsKey(n)) {
|
||||
return map.get(n);
|
||||
if (CACHE.containsKey(n)) {
|
||||
return CACHE.get(n);
|
||||
}
|
||||
|
||||
int f;
|
||||
@ -40,7 +40,7 @@ public class Fibonacci {
|
||||
f = n;
|
||||
} else {
|
||||
f = fibMemo(n - 1) + fibMemo(n - 2);
|
||||
map.put(n, f);
|
||||
CACHE.put(n, f);
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
@ -6,8 +6,8 @@ import java.util.Scanner;
|
||||
|
||||
public class MatrixChainMultiplication {
|
||||
|
||||
private static final Scanner scan = new Scanner(System.in);
|
||||
private static final ArrayList<Matrix> mArray = new ArrayList<>();
|
||||
private static final Scanner SCANNER = new Scanner(System.in);
|
||||
private static final ArrayList<Matrix> MATRICES = new ArrayList<>();
|
||||
private static int size;
|
||||
private static int[][] m;
|
||||
private static int[][] s;
|
||||
@ -24,14 +24,14 @@ public class MatrixChainMultiplication {
|
||||
int row = Integer.parseInt(mSize[1]);
|
||||
|
||||
Matrix matrix = new Matrix(count, col, row);
|
||||
mArray.add(matrix);
|
||||
MATRICES.add(matrix);
|
||||
count++;
|
||||
}
|
||||
for (Matrix m : mArray) {
|
||||
for (Matrix m : MATRICES) {
|
||||
System.out.format("A(%d) = %2d x %2d%n", m.count(), m.col(), m.row());
|
||||
}
|
||||
|
||||
size = mArray.size();
|
||||
size = MATRICES.size();
|
||||
m = new int[size + 1][size + 1];
|
||||
s = new int[size + 1][size + 1];
|
||||
p = new int[size + 1];
|
||||
@ -42,7 +42,7 @@ public class MatrixChainMultiplication {
|
||||
}
|
||||
|
||||
for (int i = 0; i < p.length; i++) {
|
||||
p[i] = i == 0 ? mArray.get(i).col() : mArray.get(i - 1).row();
|
||||
p[i] = i == 0 ? MATRICES.get(i).col() : MATRICES.get(i - 1).row();
|
||||
}
|
||||
|
||||
matrixChainOrder();
|
||||
@ -109,7 +109,7 @@ public class MatrixChainMultiplication {
|
||||
|
||||
private static String[] input(String string) {
|
||||
System.out.print(string);
|
||||
return (scan.nextLine().split(" "));
|
||||
return (SCANNER.nextLine().split(" "));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user