Advertisement
Azazavr

индекс строки с наибольшим по модулю произведением элементов

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