-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatrice.java
70 lines (65 loc) · 2.27 KB
/
Matrice.java
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import java.util.Scanner;
public class Matrice{
//public static void affichageHorizontal(int[][] mat);
public static void affichageHorizontal(int[][] mat){
for(int i = 0; i < mat.length; i++){
for(int j = 0; j < mat[i].length; j++){
System.out.print(mat[i][j]+" ");
}
System.out.println();
}
}
public static int max(int[][] mat){
int maxi = 0;
for(int i = 0; i < mat.length; i++){
if(maxi < mat[i].length){
maxi = mat[i].length;
}
}
return maxi;
}
//public static void affichageHorizontal(int[][] mat);
public static void affichageVertical(int[][] mat){
int i,j=0,k = 1;
while(j < max(mat)){
i = 0;
//tant qu'on a pas fini les vecteurs
while(i < mat.length){
//s'il y a des elements a parcourir
if(j < mat[i].length){
System.out.print(mat[i][j]+" ");
}
else{
System.out.print(" ");
}
i++;
}
System.out.println();
j++;
}
}
public static void main(String args[]){
int mat[][];
Scanner in = new Scanner(System.in);
System.out.println("Donner le nombre de vecteurs");
int n = in.nextInt();
mat = new int[n][];
for(int i = 0; i < n; i++){
System.out.println("Donner le nombre d'elements du vecteur numero "+i+" ");
int m = in.nextInt();
mat[i] = new int[m];
for(int j = 0; j < m; j++){
System.out.println("Donner la valeur de l'element "+i+", "+j+" ");
mat[i][j] = in.nextInt();
}
}
System.out.println("======================");
System.out.println("Affichage horizontal");
System.out.println("======================");
affichageHorizontal(mat);
System.out.println("======================");
System.out.println("Affichage vertical");
System.out.println("======================");
affichageVertical(mat);
}
}