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

@ -117,7 +117,7 @@ public class ColorContrastRatio {
4.878363954846178 : "Test 6 Failed - Incorrect contrast ratio.";
}
public static void main(String args[]) {
public static void main(String[] args) {
test();
}
}

View File

@ -12,11 +12,11 @@ import java.util.Scanner;
*/
public class InverseOfMatrix {
public static void main(String argv[]) {
public static void main(String[] argv) {
Scanner input = new Scanner(System.in);
System.out.println("Enter the matrix size (Square matrix only): ");
int n = input.nextInt();
double a[][] = new double[n][n];
double[][] a = new double[n][n];
System.out.println("Enter the elements of matrix: ");
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
@ -24,7 +24,7 @@ public class InverseOfMatrix {
}
}
double d[][] = invert(a);
double[][] d = invert(a);
System.out.println();
System.out.println("The inverse is: ");
for (int i = 0; i < n; ++i) {
@ -36,11 +36,11 @@ public class InverseOfMatrix {
input.close();
}
public static double[][] invert(double a[][]) {
public static double[][] invert(double[][] a) {
int n = a.length;
double x[][] = new double[n][n];
double b[][] = new double[n][n];
int index[] = new int[n];
double[][] x = new double[n][n];
double[][] b = new double[n][n];
int[] index = new int[n];
for (int i = 0; i < n; ++i) {
b[i][i] = 1;
}
@ -73,9 +73,9 @@ public class InverseOfMatrix {
// Method to carry out the partial-pivoting Gaussian
// elimination. Here index[] stores pivoting order.
public static void gaussian(double a[][], int index[]) {
public static void gaussian(double[][] a, int[] index) {
int n = index.length;
double c[] = new double[n];
double[] c = new double[n];
// Initialize the index
for (int i = 0; i < n; ++i) {

View File

@ -44,7 +44,7 @@ public class MedianOfRunningArray {
*/
MedianOfRunningArray p = new MedianOfRunningArray();
int arr[] = { 10, 7, 4, 9, 2, 3, 11, 17, 14 };
int[] arr = { 10, 7, 4, 9, 2, 3, 11, 17, 14 };
for (int i = 0; i < 9; i++) {
p.insert(arr[i]);
System.out.print(p.median() + " ");

View File

@ -13,10 +13,10 @@ import java.util.*;
*/
public class Sort012D {
public static void main(String args[]) {
public static void main(String[] args) {
Scanner np = new Scanner(System.in);
int n = np.nextInt();
int a[] = new int[n];
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = np.nextInt();
}

View File

@ -4,14 +4,14 @@ import java.util.*;
public class ThreeSumProblem {
public static void main(String args[]) {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("Enter the target sum ");
int ts = scan.nextInt();
System.out.print("Enter the number of elements in the array ");
int n = scan.nextInt();
System.out.println("Enter all your array elements:");
int arr[] = new int[n];
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = scan.nextInt();
}

View File

@ -5,14 +5,14 @@ import java.util.stream.Collectors;
public class TwoSumProblem {
public static void main(String args[]) {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("Enter the target sum ");
int ts = scan.nextInt();
System.out.print("Enter the number of elements in the array ");
int n = scan.nextInt();
System.out.println("Enter all your array elements:");
int arr[] = new int[n];
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = scan.nextInt();
}
@ -34,7 +34,7 @@ public class TwoSumProblem {
public int[] BruteForce(int[] nums, int target) {
//Brute Force Approach
int ans[] = new int[2];
int[] ans = new int[2];
for (int i = 0; i < nums.length; i++) {
for (int j = i + 1; j < nums.length; j++) {
if (nums[i] + nums[j] == target) {
@ -51,7 +51,7 @@ public class TwoSumProblem {
public int[] TwoPointer(int[] nums, int target) {
// HashMap Approach
int ans[] = new int[2];
int[] ans = new int[2];
HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>();
for (int i = 0; i < nums.length; i++) {
hm.put(i, nums[i]);
@ -90,7 +90,7 @@ public class TwoSumProblem {
public int[] HashMap(int[] nums, int target) {
//Using Hashmaps
int ans[] = new int[2];
int[] ans = new int[2];
HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>();
for (int i = 0; i < nums.length; i++) {
hm.put(nums[i], i);