Skip to content

Commit 9eaa2bb

Browse files
style: enable MultipleVariableDeclarations in checkstyle (#5175)
Co-authored-by: vaibhav <[email protected]>
1 parent 44ce6e7 commit 9eaa2bb

File tree

82 files changed

+299
-121
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+299
-121
lines changed

checkstyle.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@
167167
<module name="InnerAssignment"/>
168168
<!-- TODO <module name="MagicNumber"/> -->
169169
<!-- TODO <module name="MissingSwitchDefault"/> -->
170-
<!-- TODO <module name="MultipleVariableDeclarations"/> -->
170+
<module name="MultipleVariableDeclarations"/>
171171
<module name="SimplifyBooleanExpression"/>
172172
<module name="SimplifyBooleanReturn"/>
173173

src/main/java/com/thealgorithms/backtracking/PowerSum.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
*/
99
public class PowerSum {
1010

11-
private int count = 0, sum = 0;
11+
private int count = 0;
12+
private int sum = 0;
1213

1314
public int powSum(int N, int X) {
1415
Sum(N, X, 1);

src/main/java/com/thealgorithms/ciphers/Blowfish.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,8 @@ private void keyGenerate(String key) {
11751175

11761176
// round function
11771177
private String round(int time, String plainText) {
1178-
String left, right;
1178+
String left;
1179+
String right;
11791180
left = plainText.substring(0, 8);
11801181
right = plainText.substring(8, 16);
11811182
left = xor(left, P[time]);

src/main/java/com/thealgorithms/ciphers/DES.java

+16-7
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,15 @@ public void setKey(String key) {
7474

7575
private String[] getSubkeys(String originalKey) {
7676
StringBuilder permutedKey = new StringBuilder(); // Initial permutation of keys via pc1
77-
int i, j;
77+
int i;
78+
int j;
7879
for (i = 0; i < 56; i++) {
7980
permutedKey.append(originalKey.charAt(PC1[i] - 1));
8081
}
8182
String[] subKeys = new String[16];
8283
String initialPermutedKey = permutedKey.toString();
83-
String C0 = initialPermutedKey.substring(0, 28), D0 = initialPermutedKey.substring(28);
84+
String C0 = initialPermutedKey.substring(0, 28);
85+
String D0 = initialPermutedKey.substring(28);
8486

8587
// We will now operate on the left and right halves of the permutedKey
8688
for (i = 0; i < 16; i++) {
@@ -105,7 +107,8 @@ private String[] getSubkeys(String originalKey) {
105107
}
106108

107109
private String XOR(String a, String b) {
108-
int i, l = a.length();
110+
int i;
111+
int l = a.length();
109112
StringBuilder xor = new StringBuilder();
110113
for (i = 0; i < l; i++) {
111114
int firstBit = a.charAt(i) - 48; // 48 is '0' in ascii
@@ -116,7 +119,8 @@ private String XOR(String a, String b) {
116119
}
117120

118121
private String createPaddedString(String s, int desiredLength, char pad) {
119-
int i, l = s.length();
122+
int i;
123+
int l = s.length();
120124
StringBuilder paddedString = new StringBuilder();
121125
int diff = desiredLength - l;
122126
for (i = 0; i < diff; i++) {
@@ -165,7 +169,8 @@ private String encryptBlock(String message, String[] keys) {
165169
for (i = 0; i < 64; i++) {
166170
permutedMessage.append(message.charAt(IP[i] - 1));
167171
}
168-
String L0 = permutedMessage.substring(0, 32), R0 = permutedMessage.substring(32);
172+
String L0 = permutedMessage.substring(0, 32);
173+
String R0 = permutedMessage.substring(32);
169174

170175
// Iterate 16 times
171176
for (i = 0; i < 16; i++) {
@@ -198,7 +203,9 @@ private String decryptBlock(String message, String[] keys) {
198203
*/
199204
public String encrypt(String message) {
200205
StringBuilder encryptedMessage = new StringBuilder();
201-
int l = message.length(), i, j;
206+
int l = message.length();
207+
int i;
208+
int j;
202209
if (l % 8 != 0) {
203210
int desiredLength = (l / 8 + 1) * 8;
204211
l = desiredLength;
@@ -223,7 +230,9 @@ public String encrypt(String message) {
223230
*/
224231
public String decrypt(String message) {
225232
StringBuilder decryptedMessage = new StringBuilder();
226-
int l = message.length(), i, j;
233+
int l = message.length();
234+
int i;
235+
int j;
227236
if (l % 64 != 0) {
228237
throw new IllegalArgumentException("Encrypted message should be a multiple of 64 characters in length");
229238
}

src/main/java/com/thealgorithms/ciphers/HillCipher.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ static void encrypt(String message) {
4848
System.out.println(messageVector[i][0]);
4949
j++;
5050
}
51-
int x, i;
51+
int x;
52+
int i;
5253
for (i = 0; i < matrixSize; i++) {
5354
cipherMatrix[i][0] = 0;
5455

@@ -96,7 +97,8 @@ static void decrypt(String message) {
9697
System.out.println(messageVector[i][0]);
9798
j++;
9899
}
99-
int x, i;
100+
int x;
101+
int i;
100102
for (i = 0; i < n; i++) {
101103
plainMatrix[i][0] = 0;
102104

@@ -115,7 +117,10 @@ static void decrypt(String message) {
115117

116118
// Determinant calculator
117119
public static int determinant(int[][] a, int n) {
118-
int det = 0, sign = 1, p = 0, q = 0;
120+
int det = 0;
121+
int sign = 1;
122+
int p = 0;
123+
int q = 0;
119124

120125
if (n == 1) {
121126
det = a[0][0];

src/main/java/com/thealgorithms/conversions/AnyBaseToAnyBase.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ private AnyBaseToAnyBase() {
2727
public static void main(String[] args) {
2828
Scanner in = new Scanner(System.in);
2929
String n;
30-
int b1, b2;
30+
int b1;
31+
int b2;
3132
while (true) {
3233
try {
3334
System.out.print("Enter number: ");
@@ -132,7 +133,8 @@ public static String base2base(String n, int b1, int b2) {
132133
// Declare variables: decimal value of n,
133134
// character of base b1, character of base b2,
134135
// and the string that will be returned.
135-
int decimalValue = 0, charB2;
136+
int decimalValue = 0;
137+
int charB2;
136138
char charB1;
137139
String output = "";
138140
// Go through every character of n

src/main/java/com/thealgorithms/conversions/AnytoAny.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ public static void main(String[] args) {
1515
int sn = scn.nextInt();
1616
int sb = scn.nextInt();
1717
int db = scn.nextInt();
18-
int m = 1, dec = 0, dn = 0;
18+
int m = 1;
19+
int dec = 0;
20+
int dn = 0;
1921
while (sn != 0) {
2022
dec = dec + (sn % 10) * m;
2123
m *= sb;

src/main/java/com/thealgorithms/conversions/BinaryToDecimal.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ private BinaryToDecimal() {
1010
}
1111

1212
public static long binaryToDecimal(long binNum) {
13-
long binCopy, d, s = 0, power = 0;
13+
long binCopy;
14+
long d;
15+
long s = 0;
16+
long power = 0;
1417
binCopy = binNum;
1518
while (binCopy != 0) {
1619
d = binCopy % 10;

src/main/java/com/thealgorithms/conversions/BinaryToOctal.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public static void main(String[] args) {
3232
*/
3333
public static String convertBinaryToOctal(int binary) {
3434
String octal = "";
35-
int currBit = 0, j = 1;
35+
int currBit = 0;
36+
int j = 1;
3637
while (binary != 0) {
3738
int code3 = 0;
3839
for (int i = 0; i < 3; i++) {

src/main/java/com/thealgorithms/conversions/DecimalToBinary.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ public static void main(String[] args) {
2424
* conventional algorithm.
2525
*/
2626
public static void conventionalConversion() {
27-
int n, b = 0, c = 0, d;
27+
int n;
28+
int b = 0;
29+
int c = 0;
30+
int d;
2831
Scanner input = new Scanner(System.in);
2932
System.out.printf("Conventional conversion.%n Enter the decimal number: ");
3033
n = input.nextInt();
@@ -42,7 +45,10 @@ public static void conventionalConversion() {
4245
* algorithm
4346
*/
4447
public static void bitwiseConversion() {
45-
int n, b = 0, c = 0, d;
48+
int n;
49+
int b = 0;
50+
int c = 0;
51+
int d;
4652
Scanner input = new Scanner(System.in);
4753
System.out.printf("Bitwise conversion.%n Enter the decimal number: ");
4854
n = input.nextInt();

src/main/java/com/thealgorithms/conversions/DecimalToOctal.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ private DecimalToOctal() {
1818
// enter in a decimal value to get Octal output
1919
public static void main(String[] args) {
2020
Scanner sc = new Scanner(System.in);
21-
int n, k, d, s = 0, c = 0;
21+
int n;
22+
int k;
23+
int d;
24+
int s = 0;
25+
int c = 0;
2226
System.out.print("Decimal number: ");
2327
n = sc.nextInt();
2428
k = n;

src/main/java/com/thealgorithms/conversions/HexToOct.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ public static int decimal2octal(int q) {
5656
*/
5757
public static void main(String[] args) {
5858
String hexadecnum;
59-
int decnum, octalnum;
59+
int decnum;
60+
int octalnum;
6061
Scanner scan = new Scanner(System.in);
6162

6263
System.out.print("Enter Hexadecimal Number : ");

src/main/java/com/thealgorithms/datastructures/graphs/BellmanFord.java

+17-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class BellmanFord /*
1111
*/
1212
{
1313

14-
int vertex, edge;
14+
int vertex;
15+
int edge;
1516
private Edge[] edges;
1617
private int index = 0;
1718

@@ -23,7 +24,8 @@ class BellmanFord /*
2324

2425
class Edge {
2526

26-
int u, v;
27+
int u;
28+
int v;
2729
int w;
2830

2931
/**
@@ -58,7 +60,14 @@ public static void main(String[] args) {
5860
public void go() { // shows distance to all vertices // Interactive run for understanding the
5961
try ( // class first time. Assumes source vertex is 0 and
6062
Scanner sc = new Scanner(System.in)) {
61-
int i, v, e, u, ve, w, j, neg = 0;
63+
int i;
64+
int v;
65+
int e;
66+
int u;
67+
int ve;
68+
int w;
69+
int j;
70+
int neg = 0;
6271
System.out.println("Enter no. of vertices and edges please");
6372
v = sc.nextInt();
6473
e = sc.nextInt();
@@ -120,7 +129,11 @@ public void show(int source, int end,
120129
Edge[] arr) { // be created by using addEdge() method and passed by calling getEdgeArray()
121130
// method // Just shows results of computation, if graph is passed to it. The
122131
// graph should
123-
int i, j, v = vertex, e = edge, neg = 0;
132+
int i;
133+
int j;
134+
int v = vertex;
135+
int e = edge;
136+
int neg = 0;
124137
double[] dist = new double[v]; // Distance array for holding the finalized shortest path
125138
// distance between source
126139
// and all vertices

src/main/java/com/thealgorithms/datastructures/graphs/ConnectedComponent.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class Node {
2222

2323
class Edge {
2424

25-
Node startNode, endNode;
25+
Node startNode;
26+
Node endNode;
2627

2728
Edge(Node startNode, Node endNode) {
2829
this.startNode = startNode;
@@ -46,7 +47,8 @@ class Edge {
4647
* @param endNode the ending Node from the edge
4748
*/
4849
public void addEdge(E startNode, E endNode) {
49-
Node start = null, end = null;
50+
Node start = null;
51+
Node end = null;
5052
for (Node node : nodeList) {
5153
if (startNode.compareTo(node.name) == 0) {
5254
start = node;

src/main/java/com/thealgorithms/datastructures/graphs/Cycles.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
class Cycle {
77

8-
private int nodes, edges;
8+
private final int nodes;
9+
private final int edges;
910
private int[][] adjacencyMatrix;
1011
private boolean[] visited;
1112
ArrayList<ArrayList<Integer>> cycles = new ArrayList<ArrayList<Integer>>();
@@ -27,7 +28,8 @@ class Cycle {
2728
System.out.println("Enter the details of each edges <Start Node> <End Node>");
2829

2930
for (int i = 0; i < edges; i++) {
30-
int start, end;
31+
int start;
32+
int end;
3133
start = in.nextInt();
3234
end = in.nextInt();
3335
adjacencyMatrix[start][end] = 1;

src/main/java/com/thealgorithms/datastructures/graphs/DIJSKSTRAS_ALGORITHM.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ class dijkstras {
99
int k = 9;
1010

1111
int minDist(int[] dist, Boolean[] Set) {
12-
int min = Integer.MAX_VALUE, min_index = -1;
12+
int min = Integer.MAX_VALUE;
13+
int min_index = -1;
1314

1415
for (int r = 0; r < k; r++) {
1516
if (!Set[r] && dist[r] <= min) {

src/main/java/com/thealgorithms/datastructures/graphs/Graphs.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ public boolean removeEdge(E from, E to) {
7575
* already did
7676
*/
7777
public boolean addEdge(E from, E to) {
78-
Vertex fromV = null, toV = null;
78+
Vertex fromV = null;
79+
Vertex toV = null;
7980
for (Vertex v : vertices) {
8081
if (from.compareTo(v.data) == 0) { // see if from vertex already exists
8182
fromV = v;

src/main/java/com/thealgorithms/datastructures/graphs/HamiltonianCycle.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
*/
99
public class HamiltonianCycle {
1010

11-
private int V, pathCount;
11+
private int V;
12+
private int pathCount;
1213
private int[] cycle;
1314
private int[][] graph;
1415

src/main/java/com/thealgorithms/datastructures/graphs/PrimMST.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ class PrimMST {
1414
// value, from the set of vertices not yet included in MST
1515
int minKey(int[] key, Boolean[] mstSet) {
1616
// Initialize min value
17-
int min = Integer.MAX_VALUE, min_index = -1;
17+
int min = Integer.MAX_VALUE;
18+
int min_index = -1;
1819

1920
for (int v = 0; v < V; v++) {
2021
if (!mstSet[v] && key[v] < min) {

src/main/java/com/thealgorithms/datastructures/hashmap/hashing/HashMapCuckooHashing.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ public int hashFunction2(int key) {
6666
*/
6767

6868
public void insertKey2HashTable(int key) {
69-
Integer wrappedInt = key, temp;
70-
int hash, loopCounter = 0;
69+
Integer wrappedInt = key;
70+
Integer temp;
71+
int hash;
72+
int loopCounter = 0;
7173

7274
if (isFull()) {
7375
System.out.println("Hash table is full, lengthening & rehashing table");

src/main/java/com/thealgorithms/datastructures/hashmap/hashing/Main.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ private Main() {
77
}
88

99
public static void main(String[] args) {
10-
int choice, key;
10+
int choice;
11+
int key;
1112

1213
HashMap h = new HashMap(7);
1314
Scanner In = new Scanner(System.in);

src/main/java/com/thealgorithms/datastructures/hashmap/hashing/MainCuckooHashing.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ private MainCuckooHashing() {
77
}
88

99
public static void main(String[] args) {
10-
int choice, key;
10+
int choice;
11+
int key;
1112

1213
HashMapCuckooHashing h = new HashMapCuckooHashing(7);
1314
Scanner In = new Scanner(System.in);

0 commit comments

Comments
 (0)