2 <-- number of 2d arrays to have
3 <-- L X W of the 2d array
1 2 4 <-|
4 7 9 <-|-- Data to fill 2d array
2 1 6 <-|
2 <-- L X W of the 2d array
3 4 <-|-- Data to fill 2d array
5 9 <-|
所以我在想的是我会使用大小来添加到索引中,以便跳过已经放入数组的数据块。所以一个阵列会有 1 2 4 4 7 9 2 1 6 在它里面,我可以和其他人一起工作 3 4 5 9 香港专业教育学院尝试了这么多的方法,但它必须是递归的,并能够处理这种格式的任何数据..任何想法?
答案 0 :(得分:0)
String[size][size] myArray = new String[size][size];
int row = 0 ;
int column = 0;
BufferedReader br = null;
try {
String line;
br = new BufferedReader(new FileReader("The File Path HERE!"));
//for each line in file
while ((line= br.readLine()) != null) {
//split on white space
String[] row = line.split("\\s+");
//column index
for(int i =0; i < row.length; i++){
String context = row[i];
myArray[row][column] = context;
row++;
column++;
if(row == size) row = 0;
if(column == size) column = 0;
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null)br.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}