Advertisement
adrianodassis

Método e Matriz

Sep 2nd, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. package mm;
  2.  
  3. import java.util.Random;
  4.  
  5. public class Mm {
  6.  
  7.     public static void main(String[] args) {
  8.         int m[][] = new int[3][3];
  9.         preencher(m);
  10.         exibir(m);
  11.         System.out.println("Primeiro: " + primeiro(m));
  12.  
  13.     }
  14.  
  15.     public static void preencher(int x[][]) {
  16.         Random R = new Random();
  17.         for (int l = 0; l < x.length; l++) {
  18.             for (int c = 0; c < x[l].length; c++) {
  19.                 x[l][c] = R.nextInt(21);
  20.             }
  21.         }
  22.  
  23.     }
  24.  
  25.     public static void exibir(int a[][]) {
  26.         for (int i = 0; i < a.length; i++) {
  27.             for (int j = 0; j < a[i].length; j++) {
  28.                 System.out.print(a[i][j] + " ");
  29.             }
  30.             System.out.println(" ");
  31.  
  32.         }
  33.     }
  34.  
  35.     public static int primeiro(int m[][]) {
  36.         return m[0][0];
  37.     }
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement