Advertisement
Guest User

Matriz2D

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