Ajouter l affichage dans un matrice

master -  
 master -
Bonjour,
svp je fait un code est je veux ajouter l affichage de ce code dans un matrice svp aide moi et merci d avance
package javaapplication10;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class heuristique1 {
    //une varible statique
 public static int counter = 0;
    public static int[][] decode(Integer[] tableau) {
        int n = 6;
        int m = 6;
        int nbc = tableau[0];
        int nbl = 6;


        int[][] A = new int[n][m];
        int indice[] = new int[8];

        indice[0] = 1;
        for (int i = 1; i <= nbc; i++) {
            int j = indice[i - 1];

            indice[i] = indice[i - 1] + (2 * tableau[j]) + 1;
        }
//indice[indice.length]=tab.length;
//for (int j=0;j<nbc;j++){
//System.out.println(indice[j]);

//}



//for(int i = 0; i < indice.length-1; i++){
//for (int k=indice[i]+1;k<indice[i+1];k++)
//{
//System.out.println(tableau[k] );

//}

//}
        for (int i = 0; i < 6; i++) {
            for (int j = 0; j < m; j++) {
                A[i][j] = 0;

            }
        }


//System.out.println( "l indice est "+indice.length);

        for (int j = 0; j < m; j++) {
            int p = indice[j] + 1;
            int r = indice[j + 1];
//System.out.println("p est "+p);
//System.out.println("r est "+r);


            for (int g = p; g < r; g = g + 2) {
                int d = tableau[g] - 1;
                // System.out.println("d"+d+"j"+j+tableau[g+1]);

                A[d][j] = tableau[g + 1];

            }
        }

        for (int i = 0; i < 6; i++) {
            for (int j = 0; j < m; j++) {
                System.out.print(A[i][j]);

            }
            System.out.println("\n");
        }
        return (A);
    }
    //lire un fichier line par line ..

    public static  void affiche(String fichier) {
        String filePath = "C:\\" + fichier + ".txt";
        //int[][] B = new int[60][6];
       // int r;
      //  for ( int i = 0; i < 60; i++) {
                  //      for (int j = 0; j < 6; j++) {
                          //  B[i][j] = 0;
                   //  }
                  //  }

        ArrayList<List<String>> matrix = new ArrayList<List<String>>();
        try {
            // Création du flux bufférisé sur un FileReader, immédiatement suivi par un
            // try/finally, ce qui permet de ne fermer le flux QUE s'il le reader
            // est correctement instancié (évite les NullPointerException)
            BufferedReader buff = new BufferedReader(new FileReader(filePath));

            try {
                String line;
                // Lecture du fichier ligne par ligne. Cette boucle se termine
                // quand la méthode retourne la valeur null.
                while ((line = buff.readLine()) != null) {
                    String[] nbs = line.split(" ");
                    matrix.add(Arrays.asList(nbs));
                }

                //afficher les tableau
                //le transformer en entier au lieu de chaine
                for (List<String> tab : matrix) {
                    // System.out.println(tab);
                    Integer[] tableau = new Integer[tab.size()];
                    for (int i = 0; i < tab.size(); i++) {
                        tableau[i] = Integer.parseInt(tab.get(i));
                    }

                    //for(int  i=0;i<tab.size();i++){System.out.println(tableau[i]);}


                    
                    
                    int[][] C = decode(tableau);
                   //  int i=-1;
                   // for ( r= counter; r <= 60; r++) {

                         //      i++;
                         //     for (int j= 0; j < 6; j++){
                    //    System.arraycopy(C[i], 0, B[r], 0, 6);
                       //   C[r][j]=B[i][j];
                       // counter++;
                    
                  //  }}


                }








            } finally {
                // dans tous les cas, on ferme nos flux
                buff.close();
            }
        } catch (IOException ioe) {
            // erreur de fermeture des flux
            System.out.println("Erreur --" + ioe.toString());
        }
       //   for (int q = 0; q < 60; q++) {
         //               System.out.println();
           //             for (int j = 0; j < 6; j++) {
            //                System.out.print(B[q][j]);
                        }
                    
        
              //  }




    public static void main(String[] arg) throws IOException {


        affiche("marwa");
    }
}
A voir également:

1 réponse

master
 
le fichier est
5 1 2 6 1 3 1 1 1 2 2 2 6 4 6 3 6 5 2 6 1 1
5 1 2 6 2 3 4 6 2 3 6 5 2 6 1 1 3 3 4 2 6 6 6 2 1 1 5 5
5 3 6 5 2 6 1 1 1 2 6 1 3 1 3 5 3 3 5 2 1 2 3 4 6 2
6 3 5 3 3 5 2 1 3 6 5 2 6 1 1 1 2 6 2 1 5 3 4 2 2 6 4 6 3 3 4 2 6 6 6
6 2 3 4 6 2 1 1 2 3 3 4 2 6 6 6 1 2 6 3 6 5 2 6 1 1 2 1 3 4 2
5 1 6 1 2 1 3 4 2 3 3 4 2 6 6 6 3 2 6 5 1 1 6 1 3 1
5 2 3 4 6 2 3 3 4 2 6 6 6 3 6 5 2 6 1 1 1 2 6 2 2 6 4 6
6 1 6 1 2 1 1 5 5 3 6 6 3 6 4 3 1 1 2 3 3 4 2 6 6 6 2 2 6 4 6
6 2 3 4 6 2 3 3 4 2 6 6 6 3 5 3 3 5 2 1 1 6 1 2 2 6 4 6 2 1 3 4 2
0