我必须读入一个文件,例如:
0,11,6,0,10x11,0,5,4,7x6,5,0,2,3x0,4,2,0,12x10,7,3,12,0
所以我必须把它读入一个二维数组。
这是我的代码:
//set delimiter to commas
String r1=",";
String r2="x";
input.useDelimiter(r2);
//print file to check contents
while(input.hasNext()){
System.out.print(input.next());
}
//transfer file into matrix
int[][] graph=new int[filelength][filelength];
for (int row=0; row<graph.length;row++){
for(int column=0; column<graph[row].length;column++){
graph[row][column]=input.nextInt();
}
}
}
//close file
input.close();
}
}
我遗漏了我的代码的细节。但是我正在使用扫描仪类,并且我正在尝试使用两个定界符,以便在定界符“x”上代码更改为矩阵的另一行,在定界符“”上,代码输入矩阵的条目。