Advertisement
michael_xgrind

Função Matriz

Dec 18th, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.67 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Matriz {
  4.     public static void main(String args[]){
  5.         int l, c;
  6.        
  7.         Scanner leia = new Scanner(System.in);
  8.        
  9.         System.out.print("Entre com o numero de linhas: ");
  10.         l = leia.nextInt();
  11.         System.out.print("Entre com o numero de colunas: ");
  12.         c = leia.nextInt();
  13.        
  14.         System.out.println("\nMatriz:");
  15.         matriz(l,c);
  16.     }
  17.    
  18.     //Funcao que retorna a matriz  
  19.     public static void matriz(int l, int c) {
  20.         int mat[][] = new int [l][c];
  21.        
  22.         for(int i=0; i<l; i++){
  23.             for(int j=0; j<c; j++){
  24.                 mat[i][j] = (int)(Math.random() * 10);
  25.                 System.out.printf("%d\t", mat[i][j]);
  26.             } System.out.print("\n");
  27.         }
  28.        
  29.     }
  30.    
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement