probleme d'affichage d'une matrice
voici le code de mon programme :
Code:
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
| package se;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
import java.lang.System;
public class Analyser {
int var1=0;
int var2=0;
boolean b=false;
public Analyser() {
}
public void Analyse() throws FileNotFoundException, IOException {
int [][] matriceEntree = new int[1][1];
int [][] matriceSortie = new int[1][1];
String str;
List rulsCondion = new ArrayList();
List rulsResult = new ArrayList();
//StreamTokenizer StrTokenizer ;
StringBuffer iput;
FileReader filereader;
BufferedReader buffer;
filereader=new FileReader("c:\\BaseDesRegles");
buffer = new BufferedReader(filereader);
str=buffer.readLine();
StringTokenizer tokenizer = new StringTokenizer(str);
while( buffer.ready())
{
String Token = tokenizer.nextToken();
ajoutcolone(1, (int [][])matriceEntree);
if (Token.equalsIgnoreCase("si")) {
Token = tokenizer.nextToken();
while ( (tokenizer.hasMoreTokens()) && (!Token.equalsIgnoreCase("alors"))) {
iput = new StringBuffer();
while ( (!Token.equalsIgnoreCase("et")) &&
(!Token.equalsIgnoreCase("alors"))) {
iput.append(Token);
Token = tokenizer.nextToken();
}
//remplir matrice d'incidence d'entrée:
testRep((ArrayList)rulsCondion, Token);
if(b!=true){
rulsCondion.add(iput.toString());
ajoutligne(1,matriceEntree);
matriceEntree[var1][var2]=1;
}
matriceEntree[rulsCondion.indexOf(Token)][matriceEntree[0].length]=1;
Token = tokenizer.nextToken();
}
iput = new StringBuffer(Token);
while (tokenizer.hasMoreTokens()) {
iput.append(tokenizer.nextToken());
}
//remplir matrice d'incidence de sortie:
rulsResult.add(iput.toString());
}
str=buffer.readLine();
}
for (int i=0; i<matriceEntree.length; i++){
for(int j=0; j<matriceEntree[0].length; j++){
System.out.println(matriceEntree[i][j]);
}
}
}
public boolean testRep(ArrayList list, String s){
Boolean b=false;
for (Iterator i = list.iterator(); i.hasNext(); ) {
if(i.next()==s){
b=true;
break;
}
}
return(b);
}
public void ajoutligne(int ln,int [][]mat){
int temp[][]=new int [mat.length+1][mat[0].length];
var1=mat[0].length;
var2=mat.length+1;
for(int i=0; i<mat.length;i++){
for(int j=0; j<mat[0].length;j++){
temp[i][j]=mat[i][j];
}
}
mat = temp;
}
public void ajoutcolone(int co, int[][]mat){
int temp[][]=new int [mat.length][mat[0].length+1];
for(int i=0; i<mat.length;i++){
for(int j=0; j<mat[0].length;j++){
temp[i][j]=mat[i][j];
}
}
mat = temp;
}
public void ajoutlncol(int ln, int con, int mat[][]){
int temp[][]=new int[mat.length+1][mat[0].length+1];
for(int i=0; i<mat.length;i++){
for(int j=0; j<mat[0].length;j++){
temp[i][j]=mat[i][j];
}
}
mat = temp;
}
} |
ce programme doit afficher une matrice mais il n'affiche rien quel est le probleme à votre avis