Advertisement
cesarnascimento

matriz 4x4 valores aleatorios. maior numero e posiçao

Jun 5th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1. package matriz;
  2.  
  3. import java.util.Random;
  4.  
  5. public class matriztri {
  6.  
  7.     public static void main(String[] args) {
  8.        
  9.         int [][] numerosAleatorios = new int [4][4];
  10.        
  11.         Random numeroRandom = new Random();
  12.        
  13.         for(int i = 0; i < numerosAleatorios.length; i++){
  14.             for(int j = 0; j < numerosAleatorios[i].length; j++){
  15.                 numerosAleatorios[i][j] = numeroRandom.nextInt(100); // numeros de 0 a 100
  16.             }
  17.         }
  18.        
  19.         //int maior = Integer.MIN_VALUE; // maior valor
  20.         int maior = 0;
  21.         int linha = 0;
  22.         int col = 0;
  23.        
  24.         for(int i = 0; i < numerosAleatorios.length; i++){
  25.             for(int j = 0; j < numerosAleatorios[i].length; j++){
  26.                 if(numerosAleatorios[i][j] > maior){
  27.                     maior = numerosAleatorios[i][j];
  28.                     linha = i;
  29.                     col = j;
  30.                 }
  31.             }
  32.         }
  33.         // imprimir a matriz
  34.         for(int i = 0; i < numerosAleatorios.length; i++){
  35.             for(int j = 0; j < numerosAleatorios[i].length; j++){
  36.                 System.out.print(numerosAleatorios[i][j] + " ");
  37.                
  38.             }
  39.             System.out.println();
  40.         }
  41.        
  42.        
  43.        
  44.         System.out.println("Maior valor: "+maior);
  45.         System.out.println("Linha: "+linha);
  46.         System.out.println("Coluna: "+col);
  47.        
  48.     }
  49.     /* César N. */
  50. }
  51. //Imprimir matriz 4x4 com valores aleatórios entre 0 e 9.
  52. //Apos isso, determinar o maior número da matriz e sua posição.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement