Bonjour,
Je viens de commencer mes études en Sciences Informatiques, et nous sommes rentrés dans un chapitre que j'ai du mal a comprendre... J'ai un devoir a remettre pour ce soir et je suis completement bloqué.
Le devoir me demande créer un programme me permettant de savoir si la matrice (importée d'un fichier txt) est une matrice "diagonale" comme ils disent...
Par example :
1 5 7 8
2 19 0 9
9 2 8 10 Les "2" formes une diagonal dans la matrice...
1 1 2 3
Jusqu,à présent j'ai écris ca mais ce n'est évidemment pas correct, sinon je ne serai probablement pas la
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 public class CrossingDiagonals { public static void main(String[] args) { int N = StdIn.readInt(); int[][] Matrice = new int[N][N]; for (int i = 0 ; i < N ; i++) { for ( int j = 0 ; j < N ; j++){ Matrice[i][j] = StdIn.readInt(); } } for (int i = 0 ; i <= N - 1 ; i++) { for (int j = 0 ; j <= N - 1 ; j++) { int[][] a = new int[i][j]; if (a[i][j] == a[i + 1][j + 1]) { StdOut.println("Has a diag of : " + i); } } } } }
Merci d'avance pour votre aide !
Elia Dratwa
Partager