Skip to content

style: enable MultipleVariableDeclarations in checkstyle #5175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
<module name="InnerAssignment"/>
<!-- TODO <module name="MagicNumber"/> -->
<!-- TODO <module name="MissingSwitchDefault"/> -->
<!-- TODO <module name="MultipleVariableDeclarations"/> -->
<module name="MultipleVariableDeclarations"/>
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
*/
public class PowerSum {

private int count = 0, sum = 0;
private int count = 0;
private int sum = 0;

public int powSum(int N, int X) {
Sum(N, X, 1);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/thealgorithms/ciphers/Blowfish.java
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,8 @@ private void keyGenerate(String key) {

// round function
private String round(int time, String plainText) {
String left, right;
String left;
String right;
left = plainText.substring(0, 8);
right = plainText.substring(8, 16);
left = xor(left, P[time]);
Expand Down
23 changes: 16 additions & 7 deletions src/main/java/com/thealgorithms/ciphers/DES.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,15 @@ public void setKey(String key) {

private String[] getSubkeys(String originalKey) {
StringBuilder permutedKey = new StringBuilder(); // Initial permutation of keys via pc1
int i, j;
int i;
int j;
for (i = 0; i < 56; i++) {
permutedKey.append(originalKey.charAt(PC1[i] - 1));
}
String[] subKeys = new String[16];
String initialPermutedKey = permutedKey.toString();
String C0 = initialPermutedKey.substring(0, 28), D0 = initialPermutedKey.substring(28);
String C0 = initialPermutedKey.substring(0, 28);
String D0 = initialPermutedKey.substring(28);

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

private String XOR(String a, String b) {
int i, l = a.length();
int i;
int l = a.length();
StringBuilder xor = new StringBuilder();
for (i = 0; i < l; i++) {
int firstBit = a.charAt(i) - 48; // 48 is '0' in ascii
Expand All @@ -116,7 +119,8 @@ private String XOR(String a, String b) {
}

private String createPaddedString(String s, int desiredLength, char pad) {
int i, l = s.length();
int i;
int l = s.length();
StringBuilder paddedString = new StringBuilder();
int diff = desiredLength - l;
for (i = 0; i < diff; i++) {
Expand Down Expand Up @@ -165,7 +169,8 @@ private String encryptBlock(String message, String[] keys) {
for (i = 0; i < 64; i++) {
permutedMessage.append(message.charAt(IP[i] - 1));
}
String L0 = permutedMessage.substring(0, 32), R0 = permutedMessage.substring(32);
String L0 = permutedMessage.substring(0, 32);
String R0 = permutedMessage.substring(32);

// Iterate 16 times
for (i = 0; i < 16; i++) {
Expand Down Expand Up @@ -198,7 +203,9 @@ private String decryptBlock(String message, String[] keys) {
*/
public String encrypt(String message) {
StringBuilder encryptedMessage = new StringBuilder();
int l = message.length(), i, j;
int l = message.length();
int i;
int j;
if (l % 8 != 0) {
int desiredLength = (l / 8 + 1) * 8;
l = desiredLength;
Expand All @@ -223,7 +230,9 @@ public String encrypt(String message) {
*/
public String decrypt(String message) {
StringBuilder decryptedMessage = new StringBuilder();
int l = message.length(), i, j;
int l = message.length();
int i;
int j;
if (l % 64 != 0) {
throw new IllegalArgumentException("Encrypted message should be a multiple of 64 characters in length");
}
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/com/thealgorithms/ciphers/HillCipher.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ static void encrypt(String message) {
System.out.println(messageVector[i][0]);
j++;
}
int x, i;
int x;
int i;
for (i = 0; i < matrixSize; i++) {
cipherMatrix[i][0] = 0;

Expand Down Expand Up @@ -96,7 +97,8 @@ static void decrypt(String message) {
System.out.println(messageVector[i][0]);
j++;
}
int x, i;
int x;
int i;
for (i = 0; i < n; i++) {
plainMatrix[i][0] = 0;

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

// Determinant calculator
public static int determinant(int[][] a, int n) {
int det = 0, sign = 1, p = 0, q = 0;
int det = 0;
int sign = 1;
int p = 0;
int q = 0;

if (n == 1) {
det = a[0][0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ private AnyBaseToAnyBase() {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String n;
int b1, b2;
int b1;
int b2;
while (true) {
try {
System.out.print("Enter number: ");
Expand Down Expand Up @@ -132,7 +133,8 @@ public static String base2base(String n, int b1, int b2) {
// Declare variables: decimal value of n,
// character of base b1, character of base b2,
// and the string that will be returned.
int decimalValue = 0, charB2;
int decimalValue = 0;
int charB2;
char charB1;
String output = "";
// Go through every character of n
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/thealgorithms/conversions/AnytoAny.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public static void main(String[] args) {
int sn = scn.nextInt();
int sb = scn.nextInt();
int db = scn.nextInt();
int m = 1, dec = 0, dn = 0;
int m = 1;
int dec = 0;
int dn = 0;
while (sn != 0) {
dec = dec + (sn % 10) * m;
m *= sb;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ private BinaryToDecimal() {
}

public static long binaryToDecimal(long binNum) {
long binCopy, d, s = 0, power = 0;
long binCopy;
long d;
long s = 0;
long power = 0;
binCopy = binNum;
while (binCopy != 0) {
d = binCopy % 10;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public static void main(String[] args) {
*/
public static String convertBinaryToOctal(int binary) {
String octal = "";
int currBit = 0, j = 1;
int currBit = 0;
int j = 1;
while (binary != 0) {
int code3 = 0;
for (int i = 0; i < 3; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ public static void main(String[] args) {
* conventional algorithm.
*/
public static void conventionalConversion() {
int n, b = 0, c = 0, d;
int n;
int b = 0;
int c = 0;
int d;
Scanner input = new Scanner(System.in);
System.out.printf("Conventional conversion.%n Enter the decimal number: ");
n = input.nextInt();
Expand All @@ -42,7 +45,10 @@ public static void conventionalConversion() {
* algorithm
*/
public static void bitwiseConversion() {
int n, b = 0, c = 0, d;
int n;
int b = 0;
int c = 0;
int d;
Scanner input = new Scanner(System.in);
System.out.printf("Bitwise conversion.%n Enter the decimal number: ");
n = input.nextInt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ private DecimalToOctal() {
// enter in a decimal value to get Octal output
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n, k, d, s = 0, c = 0;
int n;
int k;
int d;
int s = 0;
int c = 0;
System.out.print("Decimal number: ");
n = sc.nextInt();
k = n;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/thealgorithms/conversions/HexToOct.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public static int decimal2octal(int q) {
*/
public static void main(String[] args) {
String hexadecnum;
int decnum, octalnum;
int decnum;
int octalnum;
Scanner scan = new Scanner(System.in);

System.out.print("Enter Hexadecimal Number : ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class BellmanFord /*
*/
{

int vertex, edge;
int vertex;
int edge;
private Edge[] edges;
private int index = 0;

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

class Edge {

int u, v;
int u;
int v;
int w;

/**
Expand Down Expand Up @@ -58,7 +60,14 @@ public static void main(String[] args) {
public void go() { // shows distance to all vertices // Interactive run for understanding the
try ( // class first time. Assumes source vertex is 0 and
Scanner sc = new Scanner(System.in)) {
int i, v, e, u, ve, w, j, neg = 0;
int i;
int v;
int e;
int u;
int ve;
int w;
int j;
int neg = 0;
System.out.println("Enter no. of vertices and edges please");
v = sc.nextInt();
e = sc.nextInt();
Expand Down Expand Up @@ -120,7 +129,11 @@ public void show(int source, int end,
Edge[] arr) { // be created by using addEdge() method and passed by calling getEdgeArray()
// method // Just shows results of computation, if graph is passed to it. The
// graph should
int i, j, v = vertex, e = edge, neg = 0;
int i;
int j;
int v = vertex;
int e = edge;
int neg = 0;
double[] dist = new double[v]; // Distance array for holding the finalized shortest path
// distance between source
// and all vertices
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class Node {

class Edge {

Node startNode, endNode;
Node startNode;
Node endNode;

Edge(Node startNode, Node endNode) {
this.startNode = startNode;
Expand All @@ -46,7 +47,8 @@ class Edge {
* @param endNode the ending Node from the edge
*/
public void addEdge(E startNode, E endNode) {
Node start = null, end = null;
Node start = null;
Node end = null;
for (Node node : nodeList) {
if (startNode.compareTo(node.name) == 0) {
start = node;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

class Cycle {

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

for (int i = 0; i < edges; i++) {
int start, end;
int start;
int end;
start = in.nextInt();
end = in.nextInt();
adjacencyMatrix[start][end] = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class dijkstras {
int k = 9;

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

for (int r = 0; r < k; r++) {
if (!Set[r] && dist[r] <= min) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public boolean removeEdge(E from, E to) {
* already did
*/
public boolean addEdge(E from, E to) {
Vertex fromV = null, toV = null;
Vertex fromV = null;
Vertex toV = null;
for (Vertex v : vertices) {
if (from.compareTo(v.data) == 0) { // see if from vertex already exists
fromV = v;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
*/
public class HamiltonianCycle {

private int V, pathCount;
private int V;
private int pathCount;
private int[] cycle;
private int[][] graph;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class PrimMST {
// value, from the set of vertices not yet included in MST
int minKey(int[] key, Boolean[] mstSet) {
// Initialize min value
int min = Integer.MAX_VALUE, min_index = -1;
int min = Integer.MAX_VALUE;
int min_index = -1;

for (int v = 0; v < V; v++) {
if (!mstSet[v] && key[v] < min) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ public int hashFunction2(int key) {
*/

public void insertKey2HashTable(int key) {
Integer wrappedInt = key, temp;
int hash, loopCounter = 0;
Integer wrappedInt = key;
Integer temp;
int hash;
int loopCounter = 0;

if (isFull()) {
System.out.println("Hash table is full, lengthening & rehashing table");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ private Main() {
}

public static void main(String[] args) {
int choice, key;
int choice;
int key;

HashMap h = new HashMap(7);
Scanner In = new Scanner(System.in);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ private MainCuckooHashing() {
}

public static void main(String[] args) {
int choice, key;
int choice;
int key;

HashMapCuckooHashing h = new HashMapCuckooHashing(7);
Scanner In = new Scanner(System.in);
Expand Down
Loading