-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEx_02_Matriz.java
More file actions
41 lines (40 loc) · 1.16 KB
/
Ex_02_Matriz.java
File metadata and controls
41 lines (40 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*2 ) Faça um procedimento que receba uma matriz passada por parâmetro e imprima essa matriz. */
import java.util.*;
import java.util.Scanner;
public class Ex_02_Matriz
{
public static void main(String[] args){
Scanner leia = new Scanner(System.in);
int linha,coluna;
System.out.print("digite o numero de linhas: ");
linha=leia.nextInt();
System.out.print("digite o numero de Colunas: ");
coluna=leia.nextInt();
int[][] matriz=new int[linha][coluna];
preencherMatriz(matriz);
imprimeMatriz(matriz);
}
public static void imprimeMatriz(int [][] matriz) {
System.out.println();
for(int i=0; i<matriz.length; i++)
{
for(int j =0; j< matriz[0].length;j++)
{
System.out.printf(" %2d ",i,j,matriz[i][j]);
}
System.out.println();
}
}
public static void preencherMatriz(int [][]matriz)
{
int num =0;
for(int i=0; i<matriz.length; i++)
{
for(int j =0; j<matriz.length; j++)
{
matriz[i][j]=num++;
}
System.out.println();
}
}
}