From 9eaa2bb7562fc6e58f9a61ad6a6679e87bb8a174 Mon Sep 17 00:00:00 2001 From: vaibhav9t1 <115015082+vaibhav9t1@users.noreply.github.com> Date: Sat, 25 May 2024 23:48:27 +0530 Subject: [PATCH] style: enable `MultipleVariableDeclarations` in checkstyle (#5175) Co-authored-by: vaibhav --- checkstyle.xml | 2 +- .../thealgorithms/backtracking/PowerSum.java | 3 ++- .../com/thealgorithms/ciphers/Blowfish.java | 3 ++- .../java/com/thealgorithms/ciphers/DES.java | 23 +++++++++++++------ .../com/thealgorithms/ciphers/HillCipher.java | 11 ++++++--- .../conversions/AnyBaseToAnyBase.java | 6 +++-- .../thealgorithms/conversions/AnytoAny.java | 4 +++- .../conversions/BinaryToDecimal.java | 5 +++- .../conversions/BinaryToOctal.java | 3 ++- .../conversions/DecimalToBinary.java | 10 ++++++-- .../conversions/DecimalToOctal.java | 6 ++++- .../thealgorithms/conversions/HexToOct.java | 3 ++- .../datastructures/graphs/BellmanFord.java | 21 +++++++++++++---- .../graphs/ConnectedComponent.java | 6 +++-- .../datastructures/graphs/Cycles.java | 6 +++-- .../graphs/DIJSKSTRAS_ALGORITHM.java | 3 ++- .../datastructures/graphs/Graphs.java | 3 ++- .../graphs/HamiltonianCycle.java | 3 ++- .../datastructures/graphs/PrimMST.java | 3 ++- .../hashmap/hashing/HashMapCuckooHashing.java | 6 +++-- .../datastructures/hashmap/hashing/Main.java | 3 ++- .../hashmap/hashing/MainCuckooHashing.java | 3 ++- .../datastructures/heaps/LeftistHeap.java | 8 ++++--- .../lists/SinglyLinkedList.java | 6 +++-- .../datastructures/trees/AVLTree.java | 4 +++- .../datastructures/trees/LCA.java | 9 +++++--- .../datastructures/trees/LazySegmentTree.java | 6 +++-- .../trees/PrintTopViewofTree.java | 3 ++- .../datastructures/trees/RedBlackBST.java | 7 ++++-- .../datastructures/trees/TreeRandomNode.java | 3 ++- .../trees/VerticalOrderTraversal.java | 3 ++- .../BinaryExponentiation.java | 3 ++- .../dynamicprogramming/EditDistance.java | 3 ++- .../dynamicprogramming/EggDropping.java | 6 +++-- .../dynamicprogramming/Fibonacci.java | 4 +++- .../dynamicprogramming/FordFulkerson.java | 3 ++- .../dynamicprogramming/KadaneAlgorithm.java | 3 ++- .../LongestCommonSubsequence.java | 3 ++- .../LongestPalindromicSubstring.java | 3 ++- .../PalindromicPartitioning.java | 4 +++- .../ShortestCommonSupersequenceLength.java | 3 ++- .../dynamicprogramming/Tribonacci.java | 4 +++- .../com/thealgorithms/io/BufferedReader.java | 3 ++- .../maths/AutomorphicNumber.java | 3 ++- .../maths/DeterminantOfMatrix.java | 5 +++- .../java/com/thealgorithms/maths/FFT.java | 3 ++- .../thealgorithms/maths/FindKthNumber.java | 3 ++- .../com/thealgorithms/maths/Gaussian.java | 6 +++-- .../com/thealgorithms/maths/KeithNumber.java | 8 ++++--- .../maths/LeastCommonMultiple.java | 3 ++- .../maths/NonRepeatingElement.java | 6 +++-- .../com/thealgorithms/maths/PollardRho.java | 4 +++- .../com/thealgorithms/maths/PrimeCheck.java | 3 ++- .../thealgorithms/misc/matrixTranspose.java | 5 +++- .../others/BankersAlgorithm.java | 3 ++- .../com/thealgorithms/others/Dijkstra.java | 6 +++-- .../thealgorithms/others/FibbonaciSeries.java | 3 ++- .../thealgorithms/others/FloydTriangle.java | 3 ++- .../thealgorithms/others/GuassLegendre.java | 5 +++- .../thealgorithms/others/KochSnowflake.java | 3 ++- .../thealgorithms/others/Krishnamurthy.java | 7 ++++-- .../others/LinearCongruentialGenerator.java | 5 +++- .../others/MiniMaxAlgorithm.java | 4 +++- .../com/thealgorithms/others/PageRank.java | 4 +++- .../others/RotateMatrixBy90Degrees.java | 3 ++- .../thealgorithms/others/SkylineProblem.java | 3 ++- .../scheduling/SJFScheduling.java | 19 +++++++++++---- .../scheduling/SRTFScheduling.java | 3 ++- .../searches/BinarySearch2dArray.java | 7 ++++-- .../searches/InterpolationSearch.java | 3 ++- .../searches/IterativeBinarySearch.java | 5 +++- .../searches/LinearSearchThread.java | 3 ++- .../searches/SaddlebackSearch.java | 5 +++- .../sorts/CocktailShakerSort.java | 3 ++- .../java/com/thealgorithms/sorts/DNFSort.java | 3 ++- .../com/thealgorithms/sorts/LinkListSort.java | 19 +++++++++++---- .../com/thealgorithms/sorts/MergeSort.java | 3 ++- .../java/com/thealgorithms/sorts/TimSort.java | 3 ++- .../stacks/LargestRectangle.java | 3 ++- .../thealgorithms/stacks/PostfixToInfix.java | 3 ++- .../strings/longestNonRepeativeSubstring.java | 4 +++- .../strings/zigZagPattern/zigZagPattern.java | 9 ++++++-- 82 files changed, 299 insertions(+), 121 deletions(-) diff --git a/checkstyle.xml b/checkstyle.xml index 03bcdb1d..b27e775f 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -167,7 +167,7 @@ - + diff --git a/src/main/java/com/thealgorithms/backtracking/PowerSum.java b/src/main/java/com/thealgorithms/backtracking/PowerSum.java index 72af17d4..29e37a1d 100644 --- a/src/main/java/com/thealgorithms/backtracking/PowerSum.java +++ b/src/main/java/com/thealgorithms/backtracking/PowerSum.java @@ -8,7 +8,8 @@ package com.thealgorithms.backtracking; */ 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); diff --git a/src/main/java/com/thealgorithms/ciphers/Blowfish.java b/src/main/java/com/thealgorithms/ciphers/Blowfish.java index fc7c5d04..d0e94720 100644 --- a/src/main/java/com/thealgorithms/ciphers/Blowfish.java +++ b/src/main/java/com/thealgorithms/ciphers/Blowfish.java @@ -1175,7 +1175,8 @@ public class Blowfish { // 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]); diff --git a/src/main/java/com/thealgorithms/ciphers/DES.java b/src/main/java/com/thealgorithms/ciphers/DES.java index d0a24f1e..d601b61d 100644 --- a/src/main/java/com/thealgorithms/ciphers/DES.java +++ b/src/main/java/com/thealgorithms/ciphers/DES.java @@ -74,13 +74,15 @@ public class DES { 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++) { @@ -105,7 +107,8 @@ public class DES { } 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 @@ -116,7 +119,8 @@ public class DES { } 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++) { @@ -165,7 +169,8 @@ public class DES { 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++) { @@ -198,7 +203,9 @@ public class DES { */ 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; @@ -223,7 +230,9 @@ public class DES { */ 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"); } diff --git a/src/main/java/com/thealgorithms/ciphers/HillCipher.java b/src/main/java/com/thealgorithms/ciphers/HillCipher.java index 14b98b3c..0ef7bc82 100644 --- a/src/main/java/com/thealgorithms/ciphers/HillCipher.java +++ b/src/main/java/com/thealgorithms/ciphers/HillCipher.java @@ -48,7 +48,8 @@ public final class HillCipher { System.out.println(messageVector[i][0]); j++; } - int x, i; + int x; + int i; for (i = 0; i < matrixSize; i++) { cipherMatrix[i][0] = 0; @@ -96,7 +97,8 @@ public final class HillCipher { System.out.println(messageVector[i][0]); j++; } - int x, i; + int x; + int i; for (i = 0; i < n; i++) { plainMatrix[i][0] = 0; @@ -115,7 +117,10 @@ public final class HillCipher { // 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]; diff --git a/src/main/java/com/thealgorithms/conversions/AnyBaseToAnyBase.java b/src/main/java/com/thealgorithms/conversions/AnyBaseToAnyBase.java index a5fc72c8..4bd9c74a 100644 --- a/src/main/java/com/thealgorithms/conversions/AnyBaseToAnyBase.java +++ b/src/main/java/com/thealgorithms/conversions/AnyBaseToAnyBase.java @@ -27,7 +27,8 @@ public final class 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: "); @@ -132,7 +133,8 @@ public final class AnyBaseToAnyBase { // 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 diff --git a/src/main/java/com/thealgorithms/conversions/AnytoAny.java b/src/main/java/com/thealgorithms/conversions/AnytoAny.java index 609a8156..801e4930 100644 --- a/src/main/java/com/thealgorithms/conversions/AnytoAny.java +++ b/src/main/java/com/thealgorithms/conversions/AnytoAny.java @@ -15,7 +15,9 @@ public final class AnytoAny { 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; diff --git a/src/main/java/com/thealgorithms/conversions/BinaryToDecimal.java b/src/main/java/com/thealgorithms/conversions/BinaryToDecimal.java index 57d49d7b..67b815ab 100644 --- a/src/main/java/com/thealgorithms/conversions/BinaryToDecimal.java +++ b/src/main/java/com/thealgorithms/conversions/BinaryToDecimal.java @@ -10,7 +10,10 @@ final class 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; diff --git a/src/main/java/com/thealgorithms/conversions/BinaryToOctal.java b/src/main/java/com/thealgorithms/conversions/BinaryToOctal.java index f171cdf6..6fef0902 100644 --- a/src/main/java/com/thealgorithms/conversions/BinaryToOctal.java +++ b/src/main/java/com/thealgorithms/conversions/BinaryToOctal.java @@ -32,7 +32,8 @@ public final class BinaryToOctal { */ 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++) { diff --git a/src/main/java/com/thealgorithms/conversions/DecimalToBinary.java b/src/main/java/com/thealgorithms/conversions/DecimalToBinary.java index 329985a0..471724ff 100644 --- a/src/main/java/com/thealgorithms/conversions/DecimalToBinary.java +++ b/src/main/java/com/thealgorithms/conversions/DecimalToBinary.java @@ -24,7 +24,10 @@ final class DecimalToBinary { * 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(); @@ -42,7 +45,10 @@ final class DecimalToBinary { * 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(); diff --git a/src/main/java/com/thealgorithms/conversions/DecimalToOctal.java b/src/main/java/com/thealgorithms/conversions/DecimalToOctal.java index 1d0a6f1a..4bc3a6e7 100644 --- a/src/main/java/com/thealgorithms/conversions/DecimalToOctal.java +++ b/src/main/java/com/thealgorithms/conversions/DecimalToOctal.java @@ -18,7 +18,11 @@ public final class 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; diff --git a/src/main/java/com/thealgorithms/conversions/HexToOct.java b/src/main/java/com/thealgorithms/conversions/HexToOct.java index b4994ae0..97a8be16 100644 --- a/src/main/java/com/thealgorithms/conversions/HexToOct.java +++ b/src/main/java/com/thealgorithms/conversions/HexToOct.java @@ -56,7 +56,8 @@ public final class HexToOct { */ 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 : "); diff --git a/src/main/java/com/thealgorithms/datastructures/graphs/BellmanFord.java b/src/main/java/com/thealgorithms/datastructures/graphs/BellmanFord.java index b4420b3e..a84a3cef 100644 --- a/src/main/java/com/thealgorithms/datastructures/graphs/BellmanFord.java +++ b/src/main/java/com/thealgorithms/datastructures/graphs/BellmanFord.java @@ -11,7 +11,8 @@ class BellmanFord /* */ { - int vertex, edge; + int vertex; + int edge; private Edge[] edges; private int index = 0; @@ -23,7 +24,8 @@ class BellmanFord /* class Edge { - int u, v; + int u; + int v; int w; /** @@ -58,7 +60,14 @@ class BellmanFord /* 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(); @@ -120,7 +129,11 @@ class BellmanFord /* 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 diff --git a/src/main/java/com/thealgorithms/datastructures/graphs/ConnectedComponent.java b/src/main/java/com/thealgorithms/datastructures/graphs/ConnectedComponent.java index dadab2e5..d2b76e8e 100644 --- a/src/main/java/com/thealgorithms/datastructures/graphs/ConnectedComponent.java +++ b/src/main/java/com/thealgorithms/datastructures/graphs/ConnectedComponent.java @@ -22,7 +22,8 @@ class Graph> { class Edge { - Node startNode, endNode; + Node startNode; + Node endNode; Edge(Node startNode, Node endNode) { this.startNode = startNode; @@ -46,7 +47,8 @@ class Graph> { * @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; diff --git a/src/main/java/com/thealgorithms/datastructures/graphs/Cycles.java b/src/main/java/com/thealgorithms/datastructures/graphs/Cycles.java index 06debf3d..b67c5512 100644 --- a/src/main/java/com/thealgorithms/datastructures/graphs/Cycles.java +++ b/src/main/java/com/thealgorithms/datastructures/graphs/Cycles.java @@ -5,7 +5,8 @@ import java.util.Scanner; class Cycle { - private int nodes, edges; + private final int nodes; + private final int edges; private int[][] adjacencyMatrix; private boolean[] visited; ArrayList> cycles = new ArrayList>(); @@ -27,7 +28,8 @@ class Cycle { System.out.println("Enter the details of each edges "); for (int i = 0; i < edges; i++) { - int start, end; + int start; + int end; start = in.nextInt(); end = in.nextInt(); adjacencyMatrix[start][end] = 1; diff --git a/src/main/java/com/thealgorithms/datastructures/graphs/DIJSKSTRAS_ALGORITHM.java b/src/main/java/com/thealgorithms/datastructures/graphs/DIJSKSTRAS_ALGORITHM.java index 3eff999b..865c276f 100644 --- a/src/main/java/com/thealgorithms/datastructures/graphs/DIJSKSTRAS_ALGORITHM.java +++ b/src/main/java/com/thealgorithms/datastructures/graphs/DIJSKSTRAS_ALGORITHM.java @@ -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) { diff --git a/src/main/java/com/thealgorithms/datastructures/graphs/Graphs.java b/src/main/java/com/thealgorithms/datastructures/graphs/Graphs.java index 3a13f6a6..b0970f36 100644 --- a/src/main/java/com/thealgorithms/datastructures/graphs/Graphs.java +++ b/src/main/java/com/thealgorithms/datastructures/graphs/Graphs.java @@ -75,7 +75,8 @@ class AdjacencyListGraph> { * 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; diff --git a/src/main/java/com/thealgorithms/datastructures/graphs/HamiltonianCycle.java b/src/main/java/com/thealgorithms/datastructures/graphs/HamiltonianCycle.java index 0016abef..d12f631d 100644 --- a/src/main/java/com/thealgorithms/datastructures/graphs/HamiltonianCycle.java +++ b/src/main/java/com/thealgorithms/datastructures/graphs/HamiltonianCycle.java @@ -8,7 +8,8 @@ package com.thealgorithms.datastructures.graphs; */ public class HamiltonianCycle { - private int V, pathCount; + private int V; + private int pathCount; private int[] cycle; private int[][] graph; diff --git a/src/main/java/com/thealgorithms/datastructures/graphs/PrimMST.java b/src/main/java/com/thealgorithms/datastructures/graphs/PrimMST.java index 24fcbe7f..0d9eb87a 100644 --- a/src/main/java/com/thealgorithms/datastructures/graphs/PrimMST.java +++ b/src/main/java/com/thealgorithms/datastructures/graphs/PrimMST.java @@ -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) { diff --git a/src/main/java/com/thealgorithms/datastructures/hashmap/hashing/HashMapCuckooHashing.java b/src/main/java/com/thealgorithms/datastructures/hashmap/hashing/HashMapCuckooHashing.java index 3fa6a812..6f382766 100644 --- a/src/main/java/com/thealgorithms/datastructures/hashmap/hashing/HashMapCuckooHashing.java +++ b/src/main/java/com/thealgorithms/datastructures/hashmap/hashing/HashMapCuckooHashing.java @@ -66,8 +66,10 @@ public class HashMapCuckooHashing { */ 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"); diff --git a/src/main/java/com/thealgorithms/datastructures/hashmap/hashing/Main.java b/src/main/java/com/thealgorithms/datastructures/hashmap/hashing/Main.java index b4f0afc6..ec853af5 100644 --- a/src/main/java/com/thealgorithms/datastructures/hashmap/hashing/Main.java +++ b/src/main/java/com/thealgorithms/datastructures/hashmap/hashing/Main.java @@ -7,7 +7,8 @@ public final class 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); diff --git a/src/main/java/com/thealgorithms/datastructures/hashmap/hashing/MainCuckooHashing.java b/src/main/java/com/thealgorithms/datastructures/hashmap/hashing/MainCuckooHashing.java index 6681253d..01b6ebb8 100644 --- a/src/main/java/com/thealgorithms/datastructures/hashmap/hashing/MainCuckooHashing.java +++ b/src/main/java/com/thealgorithms/datastructures/hashmap/hashing/MainCuckooHashing.java @@ -7,7 +7,8 @@ public final class 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); diff --git a/src/main/java/com/thealgorithms/datastructures/heaps/LeftistHeap.java b/src/main/java/com/thealgorithms/datastructures/heaps/LeftistHeap.java index d21f8d6e..a48d99f8 100644 --- a/src/main/java/com/thealgorithms/datastructures/heaps/LeftistHeap.java +++ b/src/main/java/com/thealgorithms/datastructures/heaps/LeftistHeap.java @@ -13,9 +13,11 @@ import java.util.ArrayList; */ public class LeftistHeap { - private final class Node { - private int element, npl; - private Node left, right; + private static final class Node { + private final int element; + private int npl; + private Node left; + private Node right; // Node constructor setting the data element and left/right pointers to null private Node(int element) { diff --git a/src/main/java/com/thealgorithms/datastructures/lists/SinglyLinkedList.java b/src/main/java/com/thealgorithms/datastructures/lists/SinglyLinkedList.java index f379e9ec..bca3c77f 100644 --- a/src/main/java/com/thealgorithms/datastructures/lists/SinglyLinkedList.java +++ b/src/main/java/com/thealgorithms/datastructures/lists/SinglyLinkedList.java @@ -82,13 +82,15 @@ public class SinglyLinkedList implements Iterable { if (valueFirst == valueSecond) { return; } - Node previousA = null, currentA = head; + Node previousA = null; + Node currentA = head; while (currentA != null && currentA.value != valueFirst) { previousA = currentA; currentA = currentA.next; } - Node previousB = null, currentB = head; + Node previousB = null; + Node currentB = head; while (currentB != null && currentB.value != valueSecond) { previousB = currentB; currentB = currentB.next; diff --git a/src/main/java/com/thealgorithms/datastructures/trees/AVLTree.java b/src/main/java/com/thealgorithms/datastructures/trees/AVLTree.java index b56a7142..7b959b08 100644 --- a/src/main/java/com/thealgorithms/datastructures/trees/AVLTree.java +++ b/src/main/java/com/thealgorithms/datastructures/trees/AVLTree.java @@ -9,7 +9,9 @@ public class AVLTree { private int key; private int balance; private int height; - private Node left, right, parent; + private Node left; + private Node right; + private Node parent; Node(int k, Node p) { key = k; diff --git a/src/main/java/com/thealgorithms/datastructures/trees/LCA.java b/src/main/java/com/thealgorithms/datastructures/trees/LCA.java index 701077b0..95a28949 100644 --- a/src/main/java/com/thealgorithms/datastructures/trees/LCA.java +++ b/src/main/java/com/thealgorithms/datastructures/trees/LCA.java @@ -14,14 +14,16 @@ public final class LCA { ArrayList> adj = new ArrayList<>(); // v is the number of vertices and e is the number of edges - int v = SCANNER.nextInt(), e = v - 1; + int v = SCANNER.nextInt(); + int e = v - 1; for (int i = 0; i < v; i++) { adj.add(new ArrayList()); } // Storing the given tree as an adjacency list - int to, from; + int to; + int from; for (int i = 0; i < e; i++) { to = SCANNER.nextInt(); from = SCANNER.nextInt(); @@ -40,7 +42,8 @@ public final class LCA { dfs(adj, 0, -1, parent, depth); // Inputting the two vertices whose LCA is to be calculated - int v1 = SCANNER.nextInt(), v2 = SCANNER.nextInt(); + int v1 = SCANNER.nextInt(); + int v2 = SCANNER.nextInt(); // Outputting the LCA System.out.println(getLCA(v1, v2, depth, parent)); diff --git a/src/main/java/com/thealgorithms/datastructures/trees/LazySegmentTree.java b/src/main/java/com/thealgorithms/datastructures/trees/LazySegmentTree.java index 6eff3c38..1d8febff 100644 --- a/src/main/java/com/thealgorithms/datastructures/trees/LazySegmentTree.java +++ b/src/main/java/com/thealgorithms/datastructures/trees/LazySegmentTree.java @@ -10,10 +10,12 @@ public class LazySegmentTree { */ static class Node { - private final int start, end; // start and end of the segment represented by this node + private final int start; + private final int end; // start and end of the segment represented by this node private int value; // value is the sum of all elements in the range [start, end) private int lazy; // lazied value that should be added to children nodes - Node left, right; // left and right children + Node left; + Node right; // left and right children Node(int start, int end, int value) { this.start = start; diff --git a/src/main/java/com/thealgorithms/datastructures/trees/PrintTopViewofTree.java b/src/main/java/com/thealgorithms/datastructures/trees/PrintTopViewofTree.java index 0fcf1324..88343db3 100644 --- a/src/main/java/com/thealgorithms/datastructures/trees/PrintTopViewofTree.java +++ b/src/main/java/com/thealgorithms/datastructures/trees/PrintTopViewofTree.java @@ -10,7 +10,8 @@ class TreeNode { // Members int key; - TreeNode left, right; + TreeNode left; + TreeNode right; // Constructor TreeNode(int key) { diff --git a/src/main/java/com/thealgorithms/datastructures/trees/RedBlackBST.java b/src/main/java/com/thealgorithms/datastructures/trees/RedBlackBST.java index f2954f28..c7cb108d 100644 --- a/src/main/java/com/thealgorithms/datastructures/trees/RedBlackBST.java +++ b/src/main/java/com/thealgorithms/datastructures/trees/RedBlackBST.java @@ -12,8 +12,11 @@ public class RedBlackBST { private class Node { - int key = -1, color = B; - Node left = nil, right = nil, p = nil; + int key = -1; + int color = B; + Node left = nil; + Node right = nil; + Node p = nil; Node(int key) { this.key = key; diff --git a/src/main/java/com/thealgorithms/datastructures/trees/TreeRandomNode.java b/src/main/java/com/thealgorithms/datastructures/trees/TreeRandomNode.java index b1123a22..cf56731f 100644 --- a/src/main/java/com/thealgorithms/datastructures/trees/TreeRandomNode.java +++ b/src/main/java/com/thealgorithms/datastructures/trees/TreeRandomNode.java @@ -29,7 +29,8 @@ public class TreeRandomNode { private final class Node { int item; - Node left, right; + Node left; + Node right; } // Using an arraylist to store the inorder traversal of the given binary tree diff --git a/src/main/java/com/thealgorithms/datastructures/trees/VerticalOrderTraversal.java b/src/main/java/com/thealgorithms/datastructures/trees/VerticalOrderTraversal.java index 63a75f6a..c1d15390 100644 --- a/src/main/java/com/thealgorithms/datastructures/trees/VerticalOrderTraversal.java +++ b/src/main/java/com/thealgorithms/datastructures/trees/VerticalOrderTraversal.java @@ -47,7 +47,8 @@ public final class VerticalOrderTraversal { /* min and max stores leftmost and right most index to later print the tree in vertical fashion.*/ - int max = 0, min = 0; + int max = 0; + int min = 0; queue.offer(root); index.offer(0); diff --git a/src/main/java/com/thealgorithms/divideandconquer/BinaryExponentiation.java b/src/main/java/com/thealgorithms/divideandconquer/BinaryExponentiation.java index a70b16b0..7c28797c 100644 --- a/src/main/java/com/thealgorithms/divideandconquer/BinaryExponentiation.java +++ b/src/main/java/com/thealgorithms/divideandconquer/BinaryExponentiation.java @@ -28,7 +28,8 @@ public class BinaryExponentiation { // iterative function to calculate a to the power of b long power(long N, long M) { - long power = N, sum = 1; + long power = N; + long sum = 1; while (M > 0) { if ((M & 1) == 1) { sum *= power; diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/EditDistance.java b/src/main/java/com/thealgorithms/dynamicprogramming/EditDistance.java index 7a7b0f00..6db30514 100644 --- a/src/main/java/com/thealgorithms/dynamicprogramming/EditDistance.java +++ b/src/main/java/com/thealgorithms/dynamicprogramming/EditDistance.java @@ -71,7 +71,8 @@ public final class EditDistance { public static void main(String[] args) { Scanner input = new Scanner(System.in); - String s1, s2; + String s1; + String s2; System.out.println("Enter the First String"); s1 = input.nextLine(); System.out.println("Enter the Second String"); diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/EggDropping.java b/src/main/java/com/thealgorithms/dynamicprogramming/EggDropping.java index c5052242..be52ab16 100644 --- a/src/main/java/com/thealgorithms/dynamicprogramming/EggDropping.java +++ b/src/main/java/com/thealgorithms/dynamicprogramming/EggDropping.java @@ -10,7 +10,8 @@ public final class EggDropping { // min trials with n eggs and m floors public static int minTrials(int n, int m) { int[][] eggFloor = new int[n + 1][m + 1]; - int result, x; + int result; + int x; for (int i = 1; i <= n; i++) { eggFloor[i][0] = 0; // Zero trial for zero floor. @@ -41,7 +42,8 @@ public final class EggDropping { } public static void main(String[] args) { - int n = 2, m = 4; + int n = 2; + int m = 4; // result outputs min no. of trials in worst case for n eggs and m floors int result = minTrials(n, m); System.out.println(result); diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/Fibonacci.java b/src/main/java/com/thealgorithms/dynamicprogramming/Fibonacci.java index 2d768df5..5855030f 100644 --- a/src/main/java/com/thealgorithms/dynamicprogramming/Fibonacci.java +++ b/src/main/java/com/thealgorithms/dynamicprogramming/Fibonacci.java @@ -86,7 +86,9 @@ public final class Fibonacci { if (n == 0) { return 0; } - int prev = 0, res = 1, next; + int prev = 0; + int res = 1; + int next; for (int i = 2; i <= n; i++) { next = prev + res; prev = res; diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/FordFulkerson.java b/src/main/java/com/thealgorithms/dynamicprogramming/FordFulkerson.java index b57dec97..6168ec6e 100644 --- a/src/main/java/com/thealgorithms/dynamicprogramming/FordFulkerson.java +++ b/src/main/java/com/thealgorithms/dynamicprogramming/FordFulkerson.java @@ -11,7 +11,8 @@ public final class FordFulkerson { static final int INF = 987654321; // edges static int vertexCount; - static int[][] capacity, flow; + static int[][] capacity; + static int[][] flow; public static void main(String[] args) { System.out.println("Vertex Count : 6"); diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/KadaneAlgorithm.java b/src/main/java/com/thealgorithms/dynamicprogramming/KadaneAlgorithm.java index 028c06d3..573d1217 100644 --- a/src/main/java/com/thealgorithms/dynamicprogramming/KadaneAlgorithm.java +++ b/src/main/java/com/thealgorithms/dynamicprogramming/KadaneAlgorithm.java @@ -11,7 +11,8 @@ public final class KadaneAlgorithm { } public static boolean max_Sum(int[] a, int predicted_answer) { - int sum = a[0], running_sum = 0; + int sum = a[0]; + int running_sum = 0; for (int k : a) { running_sum = running_sum + k; // running sum of all the indexs are stored diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/LongestCommonSubsequence.java b/src/main/java/com/thealgorithms/dynamicprogramming/LongestCommonSubsequence.java index bf43aab4..2d1fa1d1 100644 --- a/src/main/java/com/thealgorithms/dynamicprogramming/LongestCommonSubsequence.java +++ b/src/main/java/com/thealgorithms/dynamicprogramming/LongestCommonSubsequence.java @@ -41,7 +41,8 @@ final class LongestCommonSubsequence { public static String lcsString(String str1, String str2, int[][] lcsMatrix) { StringBuilder lcs = new StringBuilder(); - int i = str1.length(), j = str2.length(); + int i = str1.length(); + int j = str2.length(); while (i > 0 && j > 0) { if (str1.charAt(i - 1) == str2.charAt(j - 1)) { lcs.append(str1.charAt(i - 1)); diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/LongestPalindromicSubstring.java b/src/main/java/com/thealgorithms/dynamicprogramming/LongestPalindromicSubstring.java index 489adcca..2101ba70 100644 --- a/src/main/java/com/thealgorithms/dynamicprogramming/LongestPalindromicSubstring.java +++ b/src/main/java/com/thealgorithms/dynamicprogramming/LongestPalindromicSubstring.java @@ -23,7 +23,8 @@ public final class LongestPalindromicSubstring { return input; } boolean[][] arr = new boolean[input.length()][input.length()]; - int start = 0, end = 0; + int start = 0; + int end = 0; for (int g = 0; g < input.length(); g++) { for (int i = 0, j = g; j < input.length(); i++, j++) { if (g == 0) { diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/PalindromicPartitioning.java b/src/main/java/com/thealgorithms/dynamicprogramming/PalindromicPartitioning.java index 2c6643e3..deb101c2 100644 --- a/src/main/java/com/thealgorithms/dynamicprogramming/PalindromicPartitioning.java +++ b/src/main/java/com/thealgorithms/dynamicprogramming/PalindromicPartitioning.java @@ -31,7 +31,9 @@ public final class PalindromicPartitioning { int[] minCuts = new int[len]; boolean[][] isPalindrome = new boolean[len][len]; - int i, j, L; // different looping variables + int i; + int j; + int L; // different looping variables // Every substring of length 1 is a palindrome for (i = 0; i < len; i++) { diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/ShortestCommonSupersequenceLength.java b/src/main/java/com/thealgorithms/dynamicprogramming/ShortestCommonSupersequenceLength.java index 68387b7d..0ba25fa1 100644 --- a/src/main/java/com/thealgorithms/dynamicprogramming/ShortestCommonSupersequenceLength.java +++ b/src/main/java/com/thealgorithms/dynamicprogramming/ShortestCommonSupersequenceLength.java @@ -23,7 +23,8 @@ final class ShortestSuperSequence { // for X[0..m - 1], Y[0..n - 1] static int lcs(String X, String Y, int m, int n) { int[][] L = new int[m + 1][n + 1]; - int i, j; + int i; + int j; // Following steps build L[m + 1][n + 1] // in bottom up fashion. Note that diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/Tribonacci.java b/src/main/java/com/thealgorithms/dynamicprogramming/Tribonacci.java index 6abd6b23..407566f4 100644 --- a/src/main/java/com/thealgorithms/dynamicprogramming/Tribonacci.java +++ b/src/main/java/com/thealgorithms/dynamicprogramming/Tribonacci.java @@ -18,7 +18,9 @@ public final class Tribonacci { if (n == 0) return 0; if (n == 1 || n == 2) return 1; - int first = 0, second = 1, third = 1; + int first = 0; + int second = 1; + int third = 1; for (int i = 3; i <= n; i++) { int next = first + second + third; diff --git a/src/main/java/com/thealgorithms/io/BufferedReader.java b/src/main/java/com/thealgorithms/io/BufferedReader.java index 477a52bb..fa0237a4 100644 --- a/src/main/java/com/thealgorithms/io/BufferedReader.java +++ b/src/main/java/com/thealgorithms/io/BufferedReader.java @@ -27,7 +27,8 @@ public class BufferedReader { /** * posRead -> indicates the next byte to read */ - private int posRead = 0, bufferPos = 0; + private int posRead = 0; + private int bufferPos = 0; private boolean foundEof = false; diff --git a/src/main/java/com/thealgorithms/maths/AutomorphicNumber.java b/src/main/java/com/thealgorithms/maths/AutomorphicNumber.java index d9dd82c7..560ce3aa 100644 --- a/src/main/java/com/thealgorithms/maths/AutomorphicNumber.java +++ b/src/main/java/com/thealgorithms/maths/AutomorphicNumber.java @@ -24,7 +24,8 @@ public final class AutomorphicNumber { public static boolean isAutomorphic(long n) { if (n < 0) return false; long square = n * n; // Calculating square of the number - long t = n, numberOfdigits = 0; + long t = n; + long numberOfdigits = 0; while (t > 0) { numberOfdigits++; // Calculating number of digits in n t /= 10; diff --git a/src/main/java/com/thealgorithms/maths/DeterminantOfMatrix.java b/src/main/java/com/thealgorithms/maths/DeterminantOfMatrix.java index 7f96af38..a2a32711 100644 --- a/src/main/java/com/thealgorithms/maths/DeterminantOfMatrix.java +++ b/src/main/java/com/thealgorithms/maths/DeterminantOfMatrix.java @@ -13,7 +13,10 @@ public final class DeterminantOfMatrix { // Determinant calculator //@return determinant of the input matrix 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]; } else { diff --git a/src/main/java/com/thealgorithms/maths/FFT.java b/src/main/java/com/thealgorithms/maths/FFT.java index 8f212547..57327554 100644 --- a/src/main/java/com/thealgorithms/maths/FFT.java +++ b/src/main/java/com/thealgorithms/maths/FFT.java @@ -24,7 +24,8 @@ public final class FFT { */ static class Complex { - private double real, img; + private double real; + private double img; /** * Default Constructor. Creates the complex number 0. diff --git a/src/main/java/com/thealgorithms/maths/FindKthNumber.java b/src/main/java/com/thealgorithms/maths/FindKthNumber.java index bf7a4985..daea3f96 100644 --- a/src/main/java/com/thealgorithms/maths/FindKthNumber.java +++ b/src/main/java/com/thealgorithms/maths/FindKthNumber.java @@ -41,7 +41,8 @@ public final class FindKthNumber { } private static int findKthMax(int[] nums, int k) { - int start = 0, end = nums.length; + int start = 0; + int end = nums.length; while (start < end) { int pivot = partition(nums, start, end); if (k == pivot) { diff --git a/src/main/java/com/thealgorithms/maths/Gaussian.java b/src/main/java/com/thealgorithms/maths/Gaussian.java index 5591bfd1..07c0f67f 100644 --- a/src/main/java/com/thealgorithms/maths/Gaussian.java +++ b/src/main/java/com/thealgorithms/maths/Gaussian.java @@ -8,7 +8,8 @@ public final class Gaussian { public static ArrayList gaussian(int mat_size, ArrayList matrix) { ArrayList answerArray = new ArrayList(); - int i, j = 0; + int i; + int j = 0; double[][] mat = new double[mat_size + 1][mat_size + 1]; double[][] x = new double[mat_size][mat_size + 1]; @@ -43,7 +44,8 @@ public final class Gaussian { // calculate the x_1, x_2, ... values of the gaussian and save it in an arraylist. public static ArrayList valueOfGaussian(int mat_size, double[][] x, double[][] mat) { ArrayList answerArray = new ArrayList(); - int i, j; + int i; + int j; for (i = 0; i < mat_size; i++) { for (j = 0; j <= mat_size; j++) { diff --git a/src/main/java/com/thealgorithms/maths/KeithNumber.java b/src/main/java/com/thealgorithms/maths/KeithNumber.java index 194c4ba3..c2d64dca 100644 --- a/src/main/java/com/thealgorithms/maths/KeithNumber.java +++ b/src/main/java/com/thealgorithms/maths/KeithNumber.java @@ -11,9 +11,10 @@ final class KeithNumber { // user-defined function that checks if the given number is Keith or not static boolean isKeith(int x) { // List stores all the digits of the X - ArrayList terms = new ArrayList(); + ArrayList terms = new ArrayList<>(); // n denotes the number of digits - int temp = x, n = 0; + int temp = x; + int n = 0; // executes until the condition becomes false while (temp > 0) { // determines the last digit of the number and add it to the List @@ -25,7 +26,8 @@ final class KeithNumber { } // reverse the List Collections.reverse(terms); - int next_term = 0, i = n; + int next_term = 0; + int i = n; // finds next term for the series // loop executes until the condition returns true while (next_term < x) { diff --git a/src/main/java/com/thealgorithms/maths/LeastCommonMultiple.java b/src/main/java/com/thealgorithms/maths/LeastCommonMultiple.java index 228ff0b5..db79340f 100644 --- a/src/main/java/com/thealgorithms/maths/LeastCommonMultiple.java +++ b/src/main/java/com/thealgorithms/maths/LeastCommonMultiple.java @@ -30,7 +30,8 @@ public final class LeastCommonMultiple { * get least common multiple from two number */ public static int lcm(int num1, int num2) { - int high, num3; + int high; + int num3; int cmv = 0; /* * value selection for the numerator diff --git a/src/main/java/com/thealgorithms/maths/NonRepeatingElement.java b/src/main/java/com/thealgorithms/maths/NonRepeatingElement.java index ee92470c..f58a56aa 100644 --- a/src/main/java/com/thealgorithms/maths/NonRepeatingElement.java +++ b/src/main/java/com/thealgorithms/maths/NonRepeatingElement.java @@ -13,7 +13,8 @@ public final class NonRepeatingElement { public static void main(String[] args) { try (Scanner sc = new Scanner(System.in)) { - int i, res = 0; + int i; + int res = 0; System.out.println("Enter the number of elements in the array"); int n = sc.nextInt(); if ((n & 1) == 1) { @@ -42,7 +43,8 @@ public final class NonRepeatingElement { // Finding the rightmost set bit res = res & (-res); - int num1 = 0, num2 = 0; + int num1 = 0; + int num2 = 0; for (i = 0; i < n; i++) { if ((res & arr[i]) > 0) { // Case 1 explained below diff --git a/src/main/java/com/thealgorithms/maths/PollardRho.java b/src/main/java/com/thealgorithms/maths/PollardRho.java index 8855a463..7fa913b2 100644 --- a/src/main/java/com/thealgorithms/maths/PollardRho.java +++ b/src/main/java/com/thealgorithms/maths/PollardRho.java @@ -59,7 +59,9 @@ public final class PollardRho { * @throws RuntimeException object if GCD of given number cannot be found */ static int pollardRho(int number) { - int x = 2, y = 2, d = 1; + int x = 2; + int y = 2; + int d = 1; while (d == 1) { // tortoise move x = g(x, number); diff --git a/src/main/java/com/thealgorithms/maths/PrimeCheck.java b/src/main/java/com/thealgorithms/maths/PrimeCheck.java index 4f928bfe..628a819a 100644 --- a/src/main/java/com/thealgorithms/maths/PrimeCheck.java +++ b/src/main/java/com/thealgorithms/maths/PrimeCheck.java @@ -56,7 +56,8 @@ public final class PrimeCheck { */ public static boolean fermatPrimeChecking(int n, int iteration) { long a; - int up = n - 2, down = 2; + int up = n - 2; + int down = 2; for (int i = 0; i < iteration; i++) { a = (long) Math.floor(Math.random() * (up - down + 1) + down); if (modPow(a, n - 1, n) != 1) { diff --git a/src/main/java/com/thealgorithms/misc/matrixTranspose.java b/src/main/java/com/thealgorithms/misc/matrixTranspose.java index bf81675a..40634f18 100644 --- a/src/main/java/com/thealgorithms/misc/matrixTranspose.java +++ b/src/main/java/com/thealgorithms/misc/matrixTranspose.java @@ -31,7 +31,10 @@ public final class matrixTranspose { * @return Nothing. */ Scanner sc = new Scanner(System.in); - int i, j, row, column; + int i; + int j; + int row; + int column; System.out.println("Enter the number of rows in the 2D matrix:"); /* diff --git a/src/main/java/com/thealgorithms/others/BankersAlgorithm.java b/src/main/java/com/thealgorithms/others/BankersAlgorithm.java index fb699d89..baa18043 100644 --- a/src/main/java/com/thealgorithms/others/BankersAlgorithm.java +++ b/src/main/java/com/thealgorithms/others/BankersAlgorithm.java @@ -113,7 +113,8 @@ public final class BankersAlgorithm { * This is main method of Banker's Algorithm */ public static void main(String[] args) { - int numberOfProcesses, numberOfResources; + int numberOfProcesses; + int numberOfResources; Scanner sc = new Scanner(System.in); diff --git a/src/main/java/com/thealgorithms/others/Dijkstra.java b/src/main/java/com/thealgorithms/others/Dijkstra.java index 56fc32a9..e2a778f8 100644 --- a/src/main/java/com/thealgorithms/others/Dijkstra.java +++ b/src/main/java/com/thealgorithms/others/Dijkstra.java @@ -63,7 +63,8 @@ class Graph { */ public static class Edge { - public final String v1, v2; + public final String v1; + public final String v2; public final int dist; Edge(String v1, String v2, int dist) { @@ -198,7 +199,8 @@ class Graph { * Implementation of dijkstra's algorithm using a binary heap. */ private void dijkstra(final NavigableSet q) { - Vertex u, v; + Vertex u; + Vertex v; while (!q.isEmpty()) { // vertex with shortest distance (first iteration will return source) u = q.pollFirst(); diff --git a/src/main/java/com/thealgorithms/others/FibbonaciSeries.java b/src/main/java/com/thealgorithms/others/FibbonaciSeries.java index bb1500e5..a4815296 100644 --- a/src/main/java/com/thealgorithms/others/FibbonaciSeries.java +++ b/src/main/java/com/thealgorithms/others/FibbonaciSeries.java @@ -23,7 +23,8 @@ public final class FibbonaciSeries { // Get input from the user Scanner scan = new Scanner(System.in); int n = scan.nextInt(); - int first = 0, second = 1; + int first = 0; + int second = 1; scan.close(); while (first <= n) { // print first fibo 0 then add second fibo into it while updating second as well diff --git a/src/main/java/com/thealgorithms/others/FloydTriangle.java b/src/main/java/com/thealgorithms/others/FloydTriangle.java index 9e887983..fbeaec33 100644 --- a/src/main/java/com/thealgorithms/others/FloydTriangle.java +++ b/src/main/java/com/thealgorithms/others/FloydTriangle.java @@ -9,7 +9,8 @@ final class FloydTriangle { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter the number of rows which you want in your Floyd Triangle: "); - int r = sc.nextInt(), n = 0; + int r = sc.nextInt(); + int n = 0; sc.close(); for (int i = 0; i < r; i++) { for (int j = 0; j <= i; j++) { diff --git a/src/main/java/com/thealgorithms/others/GuassLegendre.java b/src/main/java/com/thealgorithms/others/GuassLegendre.java index 5d2d585d..5ecfdf2b 100644 --- a/src/main/java/com/thealgorithms/others/GuassLegendre.java +++ b/src/main/java/com/thealgorithms/others/GuassLegendre.java @@ -21,7 +21,10 @@ public final class GuassLegendre { * l: No of loops to run */ - double a = 1, b = Math.pow(2, -0.5), t = 0.25, p = 1; + double a = 1; + double b = Math.pow(2, -0.5); + double t = 0.25; + double p = 1; for (int i = 0; i < l; ++i) { double[] temp = update(a, b, t, p); a = temp[0]; diff --git a/src/main/java/com/thealgorithms/others/KochSnowflake.java b/src/main/java/com/thealgorithms/others/KochSnowflake.java index 1762d6cf..ab426bb0 100644 --- a/src/main/java/com/thealgorithms/others/KochSnowflake.java +++ b/src/main/java/com/thealgorithms/others/KochSnowflake.java @@ -178,7 +178,8 @@ public final class KochSnowflake { */ private static class Vector2 { - double x, y; + double x; + double y; Vector2(double x, double y) { this.x = x; diff --git a/src/main/java/com/thealgorithms/others/Krishnamurthy.java b/src/main/java/com/thealgorithms/others/Krishnamurthy.java index 465d7e9c..8e5ba7c6 100644 --- a/src/main/java/com/thealgorithms/others/Krishnamurthy.java +++ b/src/main/java/com/thealgorithms/others/Krishnamurthy.java @@ -7,7 +7,8 @@ final class Krishnamurthy { } static int fact(int n) { - int i, p = 1; + int i; + int p = 1; for (i = n; i >= 1; i--) { p = p * i; } @@ -16,7 +17,9 @@ final class Krishnamurthy { public static void main(String[] args) { Scanner sc = new Scanner(System.in); - int a, b, s = 0; + int a; + int b; + int s = 0; System.out.print("Enter the number : "); a = sc.nextInt(); int n = a; diff --git a/src/main/java/com/thealgorithms/others/LinearCongruentialGenerator.java b/src/main/java/com/thealgorithms/others/LinearCongruentialGenerator.java index 346ae9f8..36bcca3e 100644 --- a/src/main/java/com/thealgorithms/others/LinearCongruentialGenerator.java +++ b/src/main/java/com/thealgorithms/others/LinearCongruentialGenerator.java @@ -9,7 +9,10 @@ package com.thealgorithms.others; */ public class LinearCongruentialGenerator { - private double a, c, m, previousValue; + private final double a; + private final double c; + private final double m; + private double previousValue; /** * * diff --git a/src/main/java/com/thealgorithms/others/MiniMaxAlgorithm.java b/src/main/java/com/thealgorithms/others/MiniMaxAlgorithm.java index 2672dc6f..cd2cd02a 100644 --- a/src/main/java/com/thealgorithms/others/MiniMaxAlgorithm.java +++ b/src/main/java/com/thealgorithms/others/MiniMaxAlgorithm.java @@ -55,7 +55,9 @@ public class MiniMaxAlgorithm { * @return The optimal score for the player that made the first move. */ public int miniMax(int depth, boolean isMaximizer, int index, boolean verbose) { - int bestScore, score1, score2; + int bestScore; + int score1; + int score2; if (depth == height) { // Leaf node reached. return scores[index]; diff --git a/src/main/java/com/thealgorithms/others/PageRank.java b/src/main/java/com/thealgorithms/others/PageRank.java index faade993..960034fd 100644 --- a/src/main/java/com/thealgorithms/others/PageRank.java +++ b/src/main/java/com/thealgorithms/others/PageRank.java @@ -5,7 +5,9 @@ import java.util.Scanner; class PageRank { public static void main(String[] args) { - int nodes, i, j; + int nodes; + int i; + int j; Scanner in = new Scanner(System.in); System.out.print("Enter the Number of WebPages: "); nodes = in.nextInt(); diff --git a/src/main/java/com/thealgorithms/others/RotateMatrixBy90Degrees.java b/src/main/java/com/thealgorithms/others/RotateMatrixBy90Degrees.java index 985b8b26..2ea3de81 100644 --- a/src/main/java/com/thealgorithms/others/RotateMatrixBy90Degrees.java +++ b/src/main/java/com/thealgorithms/others/RotateMatrixBy90Degrees.java @@ -58,7 +58,8 @@ final class Rotate { } } } - int i = 0, k = n - 1; + int i = 0; + int k = n - 1; while (i < k) { for (int j = 0; j < n; j++) { int temp = a[i][j]; diff --git a/src/main/java/com/thealgorithms/others/SkylineProblem.java b/src/main/java/com/thealgorithms/others/SkylineProblem.java index 149adf43..ece398e7 100644 --- a/src/main/java/com/thealgorithms/others/SkylineProblem.java +++ b/src/main/java/com/thealgorithms/others/SkylineProblem.java @@ -59,7 +59,8 @@ public class SkylineProblem { } public ArrayList mergeSkyline(ArrayList sky1, ArrayList sky2) { - int currentH1 = 0, currentH2 = 0; + int currentH1 = 0; + int currentH2 = 0; ArrayList skyline = new ArrayList<>(); int maxH = 0; diff --git a/src/main/java/com/thealgorithms/scheduling/SJFScheduling.java b/src/main/java/com/thealgorithms/scheduling/SJFScheduling.java index 2bc5f54c..c14c91ba 100644 --- a/src/main/java/com/thealgorithms/scheduling/SJFScheduling.java +++ b/src/main/java/com/thealgorithms/scheduling/SJFScheduling.java @@ -24,7 +24,9 @@ public class SJFScheduling { sortByArrivalTime(); } protected void sortByArrivalTime() { - int size = processes.size(), i, j; + int size = processes.size(); + int i; + int j; ProcessDetails temp; for (i = 0; i < size; i++) { for (j = i + 1; j < size - 1; j++) { @@ -44,8 +46,12 @@ public class SJFScheduling { public void scheduleProcesses() { ArrayList ready = new ArrayList<>(); - int size = processes.size(), runtime, time = 0; - int executed = 0, j, k = 0; + int size = processes.size(); + int runtime; + int time = 0; + int executed = 0; + int j; + int k = 0; ProcessDetails running; if (size == 0) { @@ -85,8 +91,11 @@ public class SJFScheduling { if (ReadyProcesses.isEmpty()) { return null; } - int i, size = ReadyProcesses.size(); - int minBurstTime = ReadyProcesses.get(0).getBurstTime(), temp, positionOfShortestJob = 0; + int i; + int size = ReadyProcesses.size(); + int minBurstTime = ReadyProcesses.get(0).getBurstTime(); + int temp; + int positionOfShortestJob = 0; for (i = 1; i < size; i++) { temp = ReadyProcesses.get(i).getBurstTime(); diff --git a/src/main/java/com/thealgorithms/scheduling/SRTFScheduling.java b/src/main/java/com/thealgorithms/scheduling/SRTFScheduling.java index ad8aeaba..99214fff 100644 --- a/src/main/java/com/thealgorithms/scheduling/SRTFScheduling.java +++ b/src/main/java/com/thealgorithms/scheduling/SRTFScheduling.java @@ -31,7 +31,8 @@ public class SRTFScheduling { } public void evaluateScheduling() { - int time = 0, cr = 0; // cr=current running process, time= units of time + int time = 0; + int cr = 0; // cr=current running process, time= units of time int n = processes.size(); int[] remainingTime = new int[n]; diff --git a/src/main/java/com/thealgorithms/searches/BinarySearch2dArray.java b/src/main/java/com/thealgorithms/searches/BinarySearch2dArray.java index 164f906a..2794c4bd 100644 --- a/src/main/java/com/thealgorithms/searches/BinarySearch2dArray.java +++ b/src/main/java/com/thealgorithms/searches/BinarySearch2dArray.java @@ -13,13 +13,16 @@ public final class BinarySearch2dArray { } static int[] BinarySearch(int[][] arr, int target) { - int rowCount = arr.length, colCount = arr[0].length; + int rowCount = arr.length; + int colCount = arr[0].length; if (rowCount == 1) { return binarySearch(arr, target, 0, 0, colCount); } - int startRow = 0, endRow = rowCount - 1, midCol = colCount / 2; + int startRow = 0; + int endRow = rowCount - 1; + int midCol = colCount / 2; while (startRow < endRow - 1) { int midRow = startRow + (endRow - startRow) / 2; // getting the index of middle row diff --git a/src/main/java/com/thealgorithms/searches/InterpolationSearch.java b/src/main/java/com/thealgorithms/searches/InterpolationSearch.java index 215ecdef..aa1ff412 100644 --- a/src/main/java/com/thealgorithms/searches/InterpolationSearch.java +++ b/src/main/java/com/thealgorithms/searches/InterpolationSearch.java @@ -23,7 +23,8 @@ class InterpolationSearch { */ public int find(int[] array, int key) { // Find indexes of two corners - int start = 0, end = (array.length - 1); + int start = 0; + int end = (array.length - 1); // Since array is sorted, an element present // in array must be in range defined by corner diff --git a/src/main/java/com/thealgorithms/searches/IterativeBinarySearch.java b/src/main/java/com/thealgorithms/searches/IterativeBinarySearch.java index 324b8f58..49a86e4e 100644 --- a/src/main/java/com/thealgorithms/searches/IterativeBinarySearch.java +++ b/src/main/java/com/thealgorithms/searches/IterativeBinarySearch.java @@ -32,7 +32,10 @@ public final class IterativeBinarySearch implements SearchAlgorithm { */ @Override public > int find(T[] array, T key) { - int l, r, k, cmp; + int l; + int r; + int k; + int cmp; l = 0; r = array.length - 1; diff --git a/src/main/java/com/thealgorithms/searches/LinearSearchThread.java b/src/main/java/com/thealgorithms/searches/LinearSearchThread.java index d3d04e4f..b354d312 100644 --- a/src/main/java/com/thealgorithms/searches/LinearSearchThread.java +++ b/src/main/java/com/thealgorithms/searches/LinearSearchThread.java @@ -42,7 +42,8 @@ public final class LinearSearchThread { class Searcher extends Thread { private final int[] arr; - private final int left, right; + private final int left; + private final int right; private final int x; private boolean found; diff --git a/src/main/java/com/thealgorithms/searches/SaddlebackSearch.java b/src/main/java/com/thealgorithms/searches/SaddlebackSearch.java index 6ec1aa5c..5c7a914e 100644 --- a/src/main/java/com/thealgorithms/searches/SaddlebackSearch.java +++ b/src/main/java/com/thealgorithms/searches/SaddlebackSearch.java @@ -57,7 +57,10 @@ public final class SaddlebackSearch { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int[][] arr; - int i, j, rows = sc.nextInt(), col = sc.nextInt(); + int i; + int j; + int rows = sc.nextInt(); + int col = sc.nextInt(); arr = new int[rows][col]; for (i = 0; i < rows; i++) { for (j = 0; j < col; j++) { diff --git a/src/main/java/com/thealgorithms/sorts/CocktailShakerSort.java b/src/main/java/com/thealgorithms/sorts/CocktailShakerSort.java index dc3a9a10..c88c7bd0 100644 --- a/src/main/java/com/thealgorithms/sorts/CocktailShakerSort.java +++ b/src/main/java/com/thealgorithms/sorts/CocktailShakerSort.java @@ -16,7 +16,8 @@ class CocktailShakerSort implements SortAlgorithm { int length = array.length; int left = 0; int right = length - 1; - int swappedLeft, swappedRight; + int swappedLeft; + int swappedRight; while (left < right) { // front swappedRight = 0; diff --git a/src/main/java/com/thealgorithms/sorts/DNFSort.java b/src/main/java/com/thealgorithms/sorts/DNFSort.java index 7074e2cb..139f3690 100644 --- a/src/main/java/com/thealgorithms/sorts/DNFSort.java +++ b/src/main/java/com/thealgorithms/sorts/DNFSort.java @@ -9,7 +9,8 @@ public final class DNFSort { static void sort012(int[] a, int arr_size) { int low = 0; int high = arr_size - 1; - int mid = 0, temp; + int mid = 0; + int temp; while (mid <= high) { switch (a[mid]) { case 0: { diff --git a/src/main/java/com/thealgorithms/sorts/LinkListSort.java b/src/main/java/com/thealgorithms/sorts/LinkListSort.java index 14f8394b..daddae48 100644 --- a/src/main/java/com/thealgorithms/sorts/LinkListSort.java +++ b/src/main/java/com/thealgorithms/sorts/LinkListSort.java @@ -25,7 +25,10 @@ public class LinkListSort { switch (ch) { case 1: Task nm = new Task(); - Node start = null, prev = null, fresh, ptr; + Node start = null; + Node prev = null; + Node fresh; + Node ptr; for (int i = 0; i < a.length; i++) { // New nodes are created and values are added fresh = new Node(); // Node class is called @@ -50,7 +53,10 @@ public class LinkListSort { // The given array and the expected array is checked if both are same then true // is displayed else false is displayed case 2: - Node start1 = null, prev1 = null, fresh1, ptr1; + Node start1 = null; + Node prev1 = null; + Node fresh1; + Node ptr1; for (int i1 = 0; i1 < a.length; i1++) { // New nodes are created and values are added fresh1 = new Node(); // New node is created @@ -76,7 +82,10 @@ public class LinkListSort { // is displayed else false is displayed case 3: Task2 mm = new Task2(); - Node start2 = null, prev2 = null, fresh2, ptr2; + Node start2 = null; + Node prev2 = null; + Node fresh2; + Node ptr2; for (int i2 = 0; i2 < a.length; i2++) { // New nodes are created and values are added fresh2 = new Node(); // Node class is created @@ -182,7 +191,9 @@ class Task { } void task1(int[] n, int s, int m, int e) { - int i = s, k = 0, j = m + 1; + int i = s; + int k = 0; + int j = m + 1; int[] b = new int[e - s + 1]; while (i <= m && j <= e) { if (n[j] >= n[i]) diff --git a/src/main/java/com/thealgorithms/sorts/MergeSort.java b/src/main/java/com/thealgorithms/sorts/MergeSort.java index f4953e71..9949783c 100644 --- a/src/main/java/com/thealgorithms/sorts/MergeSort.java +++ b/src/main/java/com/thealgorithms/sorts/MergeSort.java @@ -50,7 +50,8 @@ class MergeSort implements SortAlgorithm { */ @SuppressWarnings("unchecked") private > void merge(T[] arr, int left, int mid, int right) { - int i = left, j = mid + 1; + int i = left; + int j = mid + 1; System.arraycopy(arr, left, aux, left, right + 1 - left); for (int k = left; k <= right; k++) { diff --git a/src/main/java/com/thealgorithms/sorts/TimSort.java b/src/main/java/com/thealgorithms/sorts/TimSort.java index bb7ed8d5..85e16636 100644 --- a/src/main/java/com/thealgorithms/sorts/TimSort.java +++ b/src/main/java/com/thealgorithms/sorts/TimSort.java @@ -31,7 +31,8 @@ class TimSort implements SortAlgorithm { } private > void merge(T[] a, int lo, int mid, int hi) { - int i = lo, j = mid + 1; + int i = lo; + int j = mid + 1; System.arraycopy(a, lo, aux, lo, hi + 1 - lo); for (int k = lo; k <= hi; k++) { diff --git a/src/main/java/com/thealgorithms/stacks/LargestRectangle.java b/src/main/java/com/thealgorithms/stacks/LargestRectangle.java index b3004a28..0404d9c9 100644 --- a/src/main/java/com/thealgorithms/stacks/LargestRectangle.java +++ b/src/main/java/com/thealgorithms/stacks/LargestRectangle.java @@ -12,7 +12,8 @@ public final class LargestRectangle { } public static String largestRectanglehistogram(int[] heights) { - int n = heights.length, maxArea = 0; + int n = heights.length; + int maxArea = 0; Stack st = new Stack<>(); for (int i = 0; i < n; i++) { int start = i; diff --git a/src/main/java/com/thealgorithms/stacks/PostfixToInfix.java b/src/main/java/com/thealgorithms/stacks/PostfixToInfix.java index 6a0453d8..114b2dc3 100644 --- a/src/main/java/com/thealgorithms/stacks/PostfixToInfix.java +++ b/src/main/java/com/thealgorithms/stacks/PostfixToInfix.java @@ -90,7 +90,8 @@ public final class PostfixToInfix { Stack stack = new Stack<>(); StringBuilder valueString = new StringBuilder(); - String operandA, operandB; + String operandA; + String operandB; char operator; for (int index = 0; index < postfix.length(); index++) { diff --git a/src/main/java/com/thealgorithms/strings/longestNonRepeativeSubstring.java b/src/main/java/com/thealgorithms/strings/longestNonRepeativeSubstring.java index 36191247..99154542 100644 --- a/src/main/java/com/thealgorithms/strings/longestNonRepeativeSubstring.java +++ b/src/main/java/com/thealgorithms/strings/longestNonRepeativeSubstring.java @@ -7,7 +7,9 @@ final class longestNonRepeativeSubstring { } public static int lengthOfLongestSubstring(String s) { - int max = 0, start = 0, i = 0; + int max = 0; + int start = 0; + int i = 0; HashMap map = new HashMap<>(); while (i < s.length()) { diff --git a/src/main/java/com/thealgorithms/strings/zigZagPattern/zigZagPattern.java b/src/main/java/com/thealgorithms/strings/zigZagPattern/zigZagPattern.java index ea366ad8..1af529f8 100644 --- a/src/main/java/com/thealgorithms/strings/zigZagPattern/zigZagPattern.java +++ b/src/main/java/com/thealgorithms/strings/zigZagPattern/zigZagPattern.java @@ -6,10 +6,15 @@ final class zigZagPattern { public static String encode(String s, int numRows) { if (numRows < 2 || s.length() < numRows) return s; - int start = 0, index = 0, height = 1, depth = numRows; + int start = 0; + int index = 0; + int height = 1; + int depth = numRows; char[] zigZagedArray = new char[s.length()]; while (depth != 0) { - int pointer = start, height_space = 2 + ((height - 2) * 2), depth_space = 2 + ((depth - 2) * 2); + int pointer = start; + int height_space = 2 + ((height - 2) * 2); + int depth_space = 2 + ((depth - 2) * 2); boolean bool = true; while (pointer < s.length()) { zigZagedArray[index++] = s.charAt(pointer);