Bonjour,
Je suis débutant sous java, je voulais faire un pgmme qui réalise des opération élementaires sur des matrices carrées : somme, produit par un nombre, affichage.
J'ai fais ce bout de code mais ca ne donne pas le résultat souhaité, je suis sur qu'il est bourré d'erreurs, j'attends vos réctifs, merci.
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
32
33
34 public class Matrice{ private int[][] mat1; public void Matrice(int[][] mat1){ this.mat1 = mat1; } private static int [][] multiplie(int m[ ][ ],int nombre) { int temp [][] = new int[m.length][m.length]; for(int i=0; i < m.length; i++){ for(int j=0; j < m.length; j++) temp [i][j] = nombre * m[i][j]; } return temp ; } public static int [] [] somme(int m1[] [],int m2[] []){ int mat1[] [] = new int[2][2]; for(int i=0;i<2;i++) for(int j=0;j<2;j++) { mat1[i][j]=m1[i][j]+m2[i][j]; } return mat1; } public static void afficher( int[][] t){ for (int i = 0 ; i < t.length ; i = i + 1 ) for (int j = 0 ; j < t.length ; j++ ) System.out.println(t[i][j]) ; } }
Partager