Advertisement
cesarnascimento

ex matriz 10x10 indicar maior e menor da linha 5/7

Jun 5th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.49 KB | None | 0 0
  1. package matriz;
  2. import java.util.Random;
  3. public class ex2loiane {
  4.  
  5.     public static void main(String[] args) {
  6.         int [][] matriz = new int [10][10];
  7.        
  8.         Random numero = new Random();
  9.        
  10.         // gerar matriz randomica
  11.         for(int i = 0; i < matriz.length; i++){
  12.             for(int j = 0; j < matriz[i].length; j++){
  13.                 matriz[i][j] = numero.nextInt(100);
  14.             }
  15.         }
  16.    
  17.         // imprimir matriz
  18.         for(int i = 0; i < matriz.length; i++){
  19.             for(int j = 0; j < matriz[i].length; j++){
  20.                 System.out.print(matriz[i][j] + " ");
  21.                
  22.             }
  23.             System.out.println();
  24.         }
  25.         // na linha 5
  26.         int maiorL5 = 0;
  27.         int menorL5 = Integer.MAX_VALUE;
  28.         for(int i = 0; i < matriz[5].length; i++){
  29.             if(matriz[5][i] > maiorL5){
  30.                 maiorL5 = matriz[5][i];
  31.             }
  32.             if(matriz[5][i] < menorL5){
  33.                 menorL5 = matriz[5][i];
  34.             }
  35.         }
  36.        
  37.         System.out.println("maior valor da linha 5: "+maiorL5);
  38.         System.out.println("menor valor da linha 5: "+menorL5);
  39.        
  40.         int maiorC7 = 0;
  41.         int menorC7 = Integer.MAX_VALUE;
  42.        
  43.         for(int i = 0; i < matriz.length; i++){
  44.             if(matriz[i][7] > maiorC7){
  45.                 maiorC7 = matriz[i][7];
  46.             }
  47.             if(matriz[i][7] < menorC7){
  48.                 menorC7 = matriz[i][7];
  49.             }
  50.         }
  51.         System.out.println("maior valor da coluna 7: "+maiorC7);
  52.         System.out.println("menor valor da coluna 7: "+menorC7);
  53.     }
  54.     /* César N. */
  55. }
  56.  
  57. //Gere e imprima uma matriz M 10x10 com valores aleatorios entre 0 e 9.
  58. //Após isso indique qual é o maior e o menor valor da linha 5
  59. //E qual é o maior e o menor valor da linha 7.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement