import java.util.Arrays; import java.util.Comparator; public class SortND { public static int[][] sort2D(int[][] array) { // 1. Trier chaque ligne for (int[] row : array) { Arrays.sort(row); } // 2. Trier les lignes par la somme de leurs éléments Arrays.sort(array, Comparator.comparingInt(SortND::sumRow)); return array; } private static int sumRow(int[] row) { int sum = 0; for (int x : row) sum += x; return sum; } public static void main(String[] args) { int[][] array = { {9, 4, 5}, {0, 3, 2}, {4, 1, 3} }; int[][] sorted = sort2D(array); System.out.println(Arrays.deepToString(sorted)); } }