Reputation: 35
this is an homework question but I have been working at it for quite a while and I must be getting slightly blind so I would really appreciate help spotting an error.
public class Maze {
int[][] grid;
private final int TRIED = 2;
private final int PATH = 3;
public Maze(String fileName) throws IOException {
BufferedReader in = new BufferedReader(new FileReader(fileName));
String s;
String [] aux= new String [2];
int x=0;
aux=in.readLine().split("\\s*[, .]\\s*");
int dimensao=Integer.parseInt(aux[0]);
String [][] gridString= new String [dimensao][dimensao];
grid= new int[dimensao][dimensao];
while ((s=in.readLine())!=null){
gridString [x]=s.split("\\s*[,.]\\s*");
x++;
System.out.println(s);
}
System.out.println();
for (int i=0;i<gridString.length;i++){
for(int j=0;j<gridString[0].length;j++){
System.out.print(gridString[i][j]+" ");
switch (gridString[i][j]) {
case "true":
grid[i][j]=1;
break;
case "false":
grid[i][j]=0;
break;
}
}
System.out.println();
}
for (int i=0;i<grid.length;i++){
for(int j=0;j<grid[0].length;j++){
System.out.print(grid[i][j]);
}
System.out.println();
}
}
and in another class class I invoke it using this an input:
5
true, false, true, false, false
true, false, true, true, true
false, false, false, false, true
true, true, false, true, true
false, false, false, true, false
The goal is to convert into an integer matrix with "true" being represented by 1 and "false" being 0. Things is my output is this
10100
10110
00000
11010
00010
And I just cant figure out what happened to the "true" values on tha last column.
Upvotes: 0
Views: 81
Reputation: 36
I think it might be the missing space in the second split - maybe reading in as " true"
Upvotes: 1