mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-07 01:35:16 +08:00
test: DeterminantOfMatrix
(#5376)
This commit is contained in:
@ -1,7 +1,5 @@
|
||||
package com.thealgorithms.maths;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/*
|
||||
* @author Ojasva Jain
|
||||
* Determinant of a Matrix Wikipedia link: https://en.wikipedia.org/wiki/Determinant
|
||||
@ -10,8 +8,13 @@ public final class DeterminantOfMatrix {
|
||||
private DeterminantOfMatrix() {
|
||||
}
|
||||
|
||||
// Determinant calculator
|
||||
//@return determinant of the input matrix
|
||||
/**
|
||||
* Calculates the determinant of a given matrix.
|
||||
*
|
||||
* @param a the input matrix
|
||||
* @param n the size of the matrix
|
||||
* @return the determinant of the matrix
|
||||
*/
|
||||
static int determinant(int[][] a, int n) {
|
||||
int det = 0;
|
||||
int sign = 1;
|
||||
@ -41,21 +44,4 @@ public final class DeterminantOfMatrix {
|
||||
}
|
||||
return det;
|
||||
}
|
||||
|
||||
// Driver Method
|
||||
public static void main(String[] args) {
|
||||
Scanner in = new Scanner(System.in);
|
||||
// Input Matrix
|
||||
System.out.println("Enter matrix size (Square matrix only)");
|
||||
int n = in.nextInt();
|
||||
System.out.println("Enter matrix");
|
||||
int[][] a = new int[n][n];
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = 0; j < n; j++) {
|
||||
a[i][j] = in.nextInt();
|
||||
}
|
||||
}
|
||||
System.out.println(determinant(a, n));
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user