Azazavr

вывести на экран значение максимального элемента массива

Feb 28th, 2015
578
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.30 KB | None | 0 0
  1. /*Создать двумерный массив из 5 строк по 8 столбцов в каждой из случайных
  2.  целых чисел из отрезка [-99;99]. Вывести массив на экран. После на отдельной
  3.  строке вывести на экран значение максимального элемента этого массива
  4.  (его индекс не имеет значения).
  5.  */
  6. public class DvumernieMassivi {
  7.     public static void main(String[] args) {
  8.         int[][] m = new int[8][5];
  9.  
  10.         for (int i = 0; i < m.length; i++) {
  11.             for (int j = 0; j <m[i].length ; j++) {
  12.                 m[i][j] = (int) ((Math.random() *200-100));
  13.             }
  14.         }
  15.  
  16.         for (int i = 0; i < m.length; i++) {
  17.             System.out.println();
  18.             for (int j = 0; j < m[i].length; j++) {
  19.                 System.out.print(m[i][j] + " ");
  20.  
  21.             }
  22.  
  23.         }
  24.         System.out.println();
  25.         int counter = 0;
  26.         for (int i = 0; i < m.length; i++) {
  27.             for (int j = 0; j < m[i].length; j++) {
  28.                 if(counter < m[i][j]) {
  29.                     counter = m[i][j];
  30.                 }
  31.  
  32.             }
  33.  
  34.         }
  35.         System.out.println("Max value = " +counter);
  36.     }
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment