Refactor Code Style (#4151)

This commit is contained in:
Saurabh Rahate
2023-04-15 13:55:54 +05:30
committed by GitHub
parent 1ce907625b
commit 1dc388653a
100 changed files with 293 additions and 319 deletions

View File

@@ -26,11 +26,11 @@ public class BankersAlgorithm {
* This method finds the need of each process
*/
static void calculateNeed(
int needArray[][],
int maxArray[][],
int allocationArray[][],
int totalProcess,
int totalResources
int[][] needArray,
int[][] maxArray,
int[][] allocationArray,
int totalProcess,
int totalResources
) {
for (int i = 0; i < totalProcess; i++) {
for (int j = 0; j < totalResources; j++) {
@@ -55,12 +55,12 @@ public class BankersAlgorithm {
* @return boolean if the system is in safe state or not
*/
static boolean checkSafeSystem(
int processes[],
int availableArray[],
int maxArray[][],
int allocationArray[][],
int totalProcess,
int totalResources
int[] processes,
int[] availableArray,
int[][] maxArray,
int[][] allocationArray,
int totalProcess,
int totalResources
) {
int[][] needArray = new int[totalProcess][totalResources];
@@ -144,14 +144,14 @@ public class BankersAlgorithm {
System.out.println("Enter total number of resources");
numberOfResources = sc.nextInt();
int processes[] = new int[numberOfProcesses];
int[] processes = new int[numberOfProcesses];
for (int i = 0; i < numberOfProcesses; i++) {
processes[i] = i;
}
System.out.println("--Enter the availability of--");
int availableArray[] = new int[numberOfResources];
int[] availableArray = new int[numberOfResources];
for (int i = 0; i < numberOfResources; i++) {
System.out.println("resource " + i + ": ");
availableArray[i] = sc.nextInt();
@@ -159,7 +159,7 @@ public class BankersAlgorithm {
System.out.println("--Enter the maximum matrix--");
int maxArray[][] = new int[numberOfProcesses][numberOfResources];
int[][] maxArray = new int[numberOfProcesses][numberOfResources];
for (int i = 0; i < numberOfProcesses; i++) {
System.out.println("For process " + i + ": ");
for (int j = 0; j < numberOfResources; j++) {
@@ -172,7 +172,7 @@ public class BankersAlgorithm {
System.out.println("--Enter the allocation matrix--");
int allocationArray[][] = new int[numberOfProcesses][numberOfResources];
int[][] allocationArray = new int[numberOfProcesses][numberOfResources];
for (int i = 0; i < numberOfProcesses; i++) {
System.out.println("For process " + i + ": ");
for (int j = 0; j < numberOfResources; j++) {

View File

@@ -35,10 +35,10 @@ public class BoyerMoore {
return -1;
}
public static void main(String args[]) {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int a[] = new int[n];
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = input.nextInt();
}

View File

@@ -38,7 +38,7 @@ public class BrianKernighanAlgorithm {
/**
* @param args : command line arguments
*/
public static void main(String args[]) {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
int setBitCount = countSetBits(num);

View File

@@ -158,9 +158,7 @@ public class CRCAlgorithm {
}
dividedMessage = (ArrayList<Integer>) x.clone();
if (!check) {
for (int z : dividedMessage) {
message.add(z);
}
message.addAll(dividedMessage);
} else {
if (dividedMessage.contains(1) && messageChanged) {
wrongMessCaught++;

View File

@@ -21,7 +21,7 @@ public class GuassLegendre {
double a = 1, b = Math.pow(2, -0.5), t = 0.25, p = 1;
for (int i = 0; i < l; ++i) {
double temp[] = update(a, b, t, p);
double[] temp = update(a, b, t, p);
a = temp[0];
b = temp[1];
t = temp[2];
@@ -32,7 +32,7 @@ public class GuassLegendre {
}
static double[] update(double a, double b, double t, double p) {
double values[] = new double[4];
double[] values = new double[4];
values[0] = (a + b) / 2;
values[1] = Math.sqrt(a * b);
values[2] = t - p * Math.pow(a - values[0], 2);

View File

@@ -10,7 +10,7 @@ class Trieac {
// Trie node
static class TrieNode {
TrieNode children[] = new TrieNode[ALPHABET_SIZE];
TrieNode[] children = new TrieNode[ALPHABET_SIZE];
// isWordEnd is true if the node represents
// end of a word

View File

@@ -8,7 +8,7 @@ public class InsertDeleteInArray {
Scanner s = new Scanner(System.in); // Input statement
System.out.println("Enter the size of the array");
int size = s.nextInt();
int a[] = new int[size];
int[] a = new int[size];
int i;
// To enter the initial elements
@@ -25,7 +25,7 @@ public class InsertDeleteInArray {
System.out.println("Enter the element to be inserted");
int ins = s.nextInt();
int size2 = size + 1;
int b[] = new int[size2];
int[] b = new int[size2];
for (i = 0; i < size2; i++) {
if (i <= insert_pos) {
b[i] = a[i];

View File

@@ -12,7 +12,7 @@ class Krishnamurthy {
return p;
}
public static void main(String args[]) {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a, b, s = 0;
System.out.print("Enter the number : ");

View File

@@ -4,7 +4,7 @@ import java.util.*;
class PageRank {
public static void main(String args[]) {
public static void main(String[] args) {
int nodes, i, j;
Scanner in = new Scanner(System.in);
System.out.print("Enter the Number of WebPages: ");
@@ -24,14 +24,14 @@ class PageRank {
p.calc(nodes);
}
public int path[][] = new int[10][10];
public double pagerank[] = new double[10];
public int[][] path = new int[10][10];
public double[] pagerank = new double[10];
public void calc(double totalNodes) {
double InitialPageRank;
double OutgoingLinks = 0;
double DampingFactor = 0.85;
double TempPageRank[] = new double[10];
double[] TempPageRank = new double[10];
int ExternalNodeNumber;
int InternalNodeNumber;
int k = 1; // For Traversing

View File

@@ -13,7 +13,7 @@ import java.util.Random;
*/
class PasswordGen {
public static void main(String args[]) {
public static void main(String[] args) {
String password = generatePassword(8, 16);
System.out.print("Password: " + password);
}

View File

@@ -119,7 +119,7 @@ public class QueueUsingTwoStacks {
*
* @param args Command line arguments
*/
public static void main(String args[]) {
public static void main(String[] args) {
QueueWithStack myQueue = new QueueWithStack();
myQueue.insert(1);
System.out.println(myQueue.peekBack()); // Will print 1

View File

@@ -29,7 +29,7 @@ class Rotate_by_90_degree {
sc.close();
}
static void printMatrix(int arr[][]) {
static void printMatrix(int[][] arr) {
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[0].length; j++) {
System.out.print(arr[i][j] + " ");
@@ -44,7 +44,7 @@ class Rotate_by_90_degree {
*/
class Rotate {
static void rotate(int a[][]) {
static void rotate(int[][] a) {
int n = a.length;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {

View File

@@ -24,14 +24,11 @@ public class StackPostfixNotation {
int num1 = s.pop();
String op = tokens.next();
if (op.equals("+")) {
s.push(num1 + num2);
} else if (op.equals("-")) {
s.push(num1 - num2);
} else if (op.equals("*")) {
s.push(num1 * num2);
} else {
s.push(num1 / num2);
switch (op) {
case "+" -> s.push(num1 + num2);
case "-" -> s.push(num1 - num2);
case "*" -> s.push(num1 * num2);
default -> s.push(num1 / num2);
}
// "+", "-", "*", "/"
}

View File

@@ -100,7 +100,7 @@ class Sudoku {
}
// Driver Code
public static void main(String args[]) {
public static void main(String[] args) {
int[][] board = new int[][] {
{ 3, 0, 6, 5, 0, 8, 4, 0, 0 },
{ 5, 2, 0, 0, 0, 0, 0, 0, 0 },

View File

@@ -18,11 +18,11 @@ import java.util.Scanner;
*/
class ThreeSum {
public static void main(String args[]) {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(); // Length of an array
int a[] = new int[n];
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();