how to access only specified portion of large n*m matrix as number of submatrices
suppose my .txt file is: data
1.0 3.1 2.1 3.4
2.4 2.0 4.6 5.1
0.2 3.3 4.7 9.1
4.0 5.4 5.1 3.2
6.1 2.1 6.4 2.6
1.2 2.0 3.5 6.9
3.1 2.5 4.6 9.8
7.1 8.1 9.4 5.1
12.1 3.1 2.5 2.4
3.8 9.1 2.1 6.7
i m having the code to print that file in 2d n*m array.now i want to print the n*m submatrix of this file . for e.g data
1.0 3.1 2.1 3.4
2.4 2.0 4.6 5.1
0.2 3.3 4.7 9.1
4.0 5.4 5.1 3.2
or i may wan开发者_如何学JAVAt to print last three rows.pls help that would be appreciable.
Sounds like you should shoot the parameters n and m into the conditions in a nested for-loop.
for(int i = 0; i < n; i++)
{
for(int j = 0; j < m; j++)
{
// access and print matrix[i][j]
}
// next line
}
Make sure you have lots of lovely bounds checking!
As for the offsets, you can initialise i and j to different values to achieve that. Again though, lots of bounds checking, or Java will scream obscenities at you.
精彩评论