mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-24 04:54:21 +08:00
Refactor Code Style (#4151)
This commit is contained in:
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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() + " ");
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user