If I understood correctly, then the problem arose when displaying the maximum value of the element of a two-dimensional array? Here is the working version:
package untitled; import java.io.*; public class Main{ public static void main(String[] args) throws java.io.IOException { int n = 5, max = 0, m = 6, maxb = 0, nn = 3, cn = 8; int[] a = new int[n]; //ΡΠΎΠ·Π΄Π°Π½ΠΈΠ΅ ΠΎΠ΄Π½ΠΎΠΌΠ΅ΡΠ½ΠΎΠ³ΠΎ ΠΌΠ°ΡΡΠΈΠ²Π° System.out.println("ΠΠ΄Π½ΠΎΠΌΠ΅ΡΠ½ΡΠΉ ΠΌΠ°ΡΡΠΈΠ²:"); for (int i = 0; i < a.length; i++) { //Π·Π°ΠΏΠΎΠ»Π½Π΅Π½ΠΈΠ΅ ΠΌΠ°ΡΡΠΈΠ²Π° ΡΠ»ΡΡΠ°ΠΉΠ½ΡΠΌΠΈ ΡΠΈΡΠ»Π°ΠΌΠΈ Π² ΠΈΠ½ΡΠ΅ΡΠ²Π°Π»Π΅ [-7; 5] a[i] = (int) Math.round((Math.random() * 13) - 7); System.out.print(a[i] + " "); } for (int i = 0; i < a.length; i++) { if (max < a[i]){ max = a[i]; } } System.out.println(" "); System.out.println("ΠΠ°ΠΊΡΠΈΠΌΠ°Π»ΡΠ½ΡΠΉ ΡΠ»Π΅ΠΌΠ΅Π½Ρ ΠΎΠ΄Π½ΠΎΠΌΠ΅ΡΠ½ΠΎΠ³ΠΎ ΠΌΠ°ΡΡΠΈΠ²Π° " + max); int[][] b = new int[n][m]; System.out.println("ΠΠ²ΡΠΌΠ΅ΡΠ½ΡΠΉ ΠΌΠ°ΡΡΠΈΠ²:"); for (int i = 0; i < b.length; i++) { for(int j = 0; j < b[i].length; j++) { b[i][j] = a[i] >> j; System.out.format("%4d", b[i][j]); } System.out.println(); } for (int i = 0; i < b.length; i++) { for(int j = 0; j < b[i].length; j++) { if (maxb < b[i][j]){ maxb = b[i][j]; } } } System.out.println("ΠΠ°ΠΊΡΠΈΠΌΠ°Π»ΡΠ½ΡΠΉ ΡΠ»Π΅ΠΌΠ΅Π½Ρ Π΄Π²ΡΠΌΠ΅ΡΠ½ΠΎΠ³ΠΎ ΠΌΠ°ΡΡΠΈΠ²Π° " + maxb); int c [][] = new int[nn][cn]; System.out.println("ΠΠ΅ΡΠ΅Π³ΡΠ»ΡΡΠ½ΡΠΉ ΠΌΠ°ΡΡΠΈΠ²:"); for(int i = 0; i < c.length; i++){ for(int j = 0; j < c[i].length; j++){ c[i][j] = 3 * i + j + maxb; System.out.format("%4d", c[i][j]); } System.out.println(); } } }
The result was in the form:
ΠΠ΄Π½ΠΎΠΌΠ΅ΡΠ½ΡΠΉ ΠΌΠ°ΡΡΠΈΠ²: -1 -5 1 6 2 ΠΠ°ΠΊΡΠΈΠΌΠ°Π»ΡΠ½ΡΠΉ ΡΠ»Π΅ΠΌΠ΅Π½Ρ ΠΎΠ΄Π½ΠΎΠΌΠ΅ΡΠ½ΠΎΠ³ΠΎ ΠΌΠ°ΡΡΠΈΠ²Π° 6 ΠΠ²ΡΠΌΠ΅ΡΠ½ΡΠΉ ΠΌΠ°ΡΡΠΈΠ²: -1 -1 -1 -1 -1 -1 -5 -3 -2 -1 -1 -1 1 0 0 0 0 0 6 3 1 0 0 0 2 1 0 0 0 0 ΠΠ°ΠΊΡΠΈΠΌΠ°Π»ΡΠ½ΡΠΉ ΡΠ»Π΅ΠΌΠ΅Π½Ρ Π΄Π²ΡΠΌΠ΅ΡΠ½ΠΎΠ³ΠΎ ΠΌΠ°ΡΡΠΈΠ²Π° 6 ΠΠ΅ΡΠ΅Π³ΡΠ»ΡΡΠ½ΡΠΉ ΠΌΠ°ΡΡΠΈΠ²: 6 7 8 9 10 11 12 13 9 10 11 12 13 14 15 16 12 13 14 15 16 17 18 19
UPDATE
The problem was with the following code snippet
for(int i = 0; i<b.length; i++){ for(int j = 0; j<b[i].length; j++){ if (b[i][maxb] < b[i][j]){ maxb=j; } } }
Namely, an error was made in the condition if (b[i][maxb] < b[i][j]) and the action performed under the condition. Based on the task of these cycles, namely the search for the maximum value of the element of a two-dimensional array, it is necessary to determine which number will be greater from the original maxb=0; for use in the following cycles. As a consequence of the error in the condition, the variable maxb remained always equal to zero, which led to a further execution error of the algorithm.
The problem was solved by correcting the condition in the given code fragment, as well as the action performed in case the condition is true.
for (int i = 0; i < b.length; i++) { for(int j = 0; j < b[i].length; j++) { if (maxb < b[i][j]){ maxb = b[i][j]; } } } System.out.println("ΠΠ°ΠΊΡΠΈΠΌΠ°Π»ΡΠ½ΡΠΉ ΡΠ»Π΅ΠΌΠ΅Π½Ρ Π΄Π²ΡΠΌΠ΅ΡΠ½ΠΎΠ³ΠΎ ΠΌΠ°ΡΡΠΈΠ²Π° " + maxb);
In this fragment, we compare the value of the variable maxb with the value of the element of a two-dimensional array. If the maxb value maxb less than the value of the array element, then this value is assigned to the maxb variable.