public class Task38 public static void main String args Scanner scanne

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
public class Task38 {
public static void main(String[] args) {
Scanner scanner = new Scanner (System.in);
int n = scanner.nextInt();
int[][] a = new int[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
a[i][j] = scanner.nextInt();
}
}
for (int i = 0; i < n; i++) {
if (a[i][i] == 0) {
int[] c = new int[n];
boolean pr = false;
for (int d = i + 1; d < n && !pr; d++) {
if (a[d][i] != 0) {
c = a[d];
a[d] = a[i];
a[i] = c;
pr = !pr;
}
}
}
int k = 1;
if (a[i][i] != 0) {
for (int x = i + 1; x < n; x++) {
k = a[x][i];
for (int j = i; j < n; j++) {
a[x][j] = a[x][j] * a[i][i] - a[i][j] * k;
}
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
System.out.print(a[i][j] + " ");
}
System.out.println();
}
}
}