
Langage JAVA 
LACHGAR Mohamed 
 
 
 
Page 4 
Correction : 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 Utilitaire{ 
 
 public static void affiche(double t[][]){ 
    for(int i = 0; i < t.length; i++){ 
   for(int j = 0; j < t[i].length; j++) 
        System.out.print(t[i][j]+"  "); 
      System.out.println(); 
    } 
  } 
 
 
 public static boolean regulier(double t[][]){ 
    boolean test = true;       
    int n = t[0].length;       
    for(int i = 1; i < t.length; i++)      
   if(n != t[i].length)  
        return false; 
    return true;        
  } 
 
 
 public static double[] sommeLignes(double t[][]){ 
    double[] total; 
    total = new double[t.length]; 
    for(int i = 0; i < t.length; i++) 
   for(int j = 0; j < t[i].length; j++)  
        total[i] += t[i][j]; 
    return total;  
  } 
  public static double[][] somme(double[][] t1, double[][] t2){ 
    double[][] t3; 
    t3 = new double[t1.length][t1[0].length]; 
    if(regulier(t1) && regulier(t2)){ 
   if(t1.length == t2.length){ 
        if(t1[0].length == t2[0].length){ 
     for(int i = 0; i < t1.length; i++) 
            for(int j = 0; j < t1[i].length; j++)  
              t3[i][j] = t1[i][j] + t2[i][j]; 
     return t3;   
        } 
        else { 
             System.out.println("Les tableaux n'ont pas le même nombres de colonnes"); 
             return null; 
          } 
      } 
   else { 
             System.out.println("Les tableaux n'ont pas le même nombres de lignes"); 
             return null; 
      } 
    } 
    else { 
        System.out.println("Les tableaux ne sont pas régulier");  
        return null; 
    } 
  } 
   
 public static void main(String[] args){ 
    double table1[][]={{1,2,3},{4,5,6},{7,8,9}}; 
    double table2[][]={{1,2,3},{4,5,6},{7,8,9}}; 
    affiche(table1); 
    if(regulier(table1))  
        System.out.println("Tableau régulier"); 
    else  
        System.out.println("Tableau non régulier"); 
    for(double i:sommeLignes(table1))  
        System.out.println(i); 
    affiche(somme(table1,table2)); 
  } 
}