Advertisement
Guest User

Matriz2D

a guest
Sep 18th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.65 KB | None | 0 0
  1. package examples;
  2.  
  3. import java.util.Random;
  4.  
  5. public class Exe {
  6.    
  7.     static int[][] array = new int[3][2];
  8.     static Random rnd = new Random();
  9.     static String numerosGenerados = "";
  10.     static void generarNumeros()
  11.     {
  12.         for(int i=0 ; i<array.length; i++)
  13.         {
  14.             for(int j=0 ; j<array[i].length; j++)
  15.             {
  16.                 int random = rnd.nextInt(101);
  17.                 array[i][j] = random;
  18.                 numerosGenerados += ""+random+",";
  19.             }
  20.         }
  21.         numerosGenerados = numerosGenerados.substring(0, numerosGenerados.length()-1);
  22.     }
  23. /**
  24. *Columnas:
  25. *{1,2,3},//columna número 0
  26. *{8,7,0},//columna número 1
  27. *{10,11,3}//columna número 2
  28.      * @param args
  29. */
  30.     public static void main(String[] args)
  31.     {
  32.         generarNumeros();
  33.        int num = 0;
  34.        int poscol = 0;
  35.        int posfil = 0;
  36.        for(int i=0 ; i<array.length ; i++)
  37.        {
  38.             for(int j=0 ; j<array[i].length; j++)
  39.             {
  40.                 if(i == 0)
  41.                 {
  42.                     num = array[i][j];
  43.                     poscol = i;
  44.                     posfil = j;
  45.                 }
  46.                 else
  47.                 {
  48.                     if(array[i][j] > num)
  49.                     {
  50.                         num = array[i][j];
  51.                         poscol = i;
  52.                         posfil = j;
  53.                     }
  54.                 }
  55.             }
  56.         }
  57.        System.err.println("Números generados: "+ numerosGenerados);
  58.        System.err.println("El número más grande es "+ num +", posición de la columna:"+poscol+", de la fila: "+ posfil);
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement