forked from sevastyan_b/SSPR_25
ready
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package ru.pyzhov.MatrixProcessing;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@Service
|
||||
public class MatrixService {
|
||||
|
||||
public int[][] sortByFirstElement(int[][] matrix) {
|
||||
Arrays.sort(matrix, (a, b) -> Integer.compare(b[0], a[0]));
|
||||
return matrix;
|
||||
}
|
||||
|
||||
public void printMatrix(int[][] matrix) {
|
||||
int rowsToPrint = Math.min(matrix.length, 10);
|
||||
int colsToPrint = matrix.length > 0 ? Math.min(matrix[0].length, 10) : 0;
|
||||
|
||||
for (int i = 0; i < rowsToPrint; i++) {
|
||||
for (int j = 0; j < colsToPrint; j++) {
|
||||
System.out.print(matrix[i][j] + " ");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user