There is a task in which you need to remove rows from a multidimensional array so that the sum of the digits left in the array approximates as a percentage of the total amount of the array to the dial set by the user in the console. What kind of algorithm did it throw ... But I can't understand why my cycle is endless? And secondly, how can I delete a line? (Convert a line to a sheet and delete? Or the entire array? (I just started to learn, so do not scold)), otherwise I just change the line that I would like to delete.
public class Task15 { public static void main(String[] args) { // Matrix percent Scanner percent = new Scanner(System.in); int percentNedded = percent.nextInt(); int percentLeft = 100; int[][] matrixRandom = Util.createRandomMatrix(10, 10, 100); for (int i = 0; i < matrixRandom.length; ++i) { System.out.println(Arrays.toString(matrixRandom[i])); } int indexOfMax = Util.rowIndexOfMaxNumber(matrixRandom);// index of max number int matrixSum = Util.matrixSumm(matrixRandom); System.out.println(matrixSum + " " + percentNedded); int row1 = 0; int row2 = matrixRandom.length - 1; while (true) { int pecentDifferent = percentLeft - percentNedded; int row1summ = Util.matrixRowSumm(matrixRandom, row1);// тут сумма строки int row2summ = Util.matrixRowSumm(matrixRandom, row2); if (row1summ > row2summ && (row1summ < pecentDifferent * matrixSum / 100) && row1 != indexOfMax) { for (int i = 0; i < matrixRandom[row1].length; i++) { matrixRandom[row1][i] = 0; } percentLeft -= row1summ / matrixSum * 100; row1++; } else { if (row2summ < pecentDifferent * matrixSum / 100 && row2 != indexOfMax) { for (int i = 0; i < matrixRandom[row2].length; i++) { matrixRandom[row2][i] = 0; } percentLeft -= row2summ / matrixSum * 100; row2--; } else break; } } for (int i = 0; i < matrixRandom.length; ++i) { System.out.println(Arrays.toString(matrixRandom[i])); } } }