Results 1 to 3 of 3
Thread: displaying 2D-Matrix
- 02-18-2009, 06:10 PM #1
Member
- Join Date
- Feb 2009
- Posts
- 26
- Rep Power
- 0
- 02-18-2009, 07:16 PM #2
Senior Member
- Join Date
- Jul 2008
- Posts
- 125
- Rep Power
- 0
This is easy, but difficult to put in print
You must set up your single for-loop
to run the duration of the entire 2D array.
!!!???
Example:
int[][] my2D = new int[5][8];
for(int i=0; i<40; i++){
...
}
Now YOU must figure out the arithmetic
within the braces that will increment two
indexes that reference the individual elements.
- 02-18-2009, 07:19 PM #3
Member
- Join Date
- Jul 2008
- Posts
- 67
- Rep Power
- 0
Hm there should be possible to write this with for loop, but this makes condition line much longer then it would be with two loops.
Why not use some own made looping method ? Or use just for-each loop this doesn't need so much typing.
Java Code:int array[][] = new int[3][3]; for (int rows = 0; rows < array.length; rows++) { for (int cols = 0; cols < array[0].length; cols++) { array[rows][cols] = cols + rows; } } for (int[] rows : array) { for (int columns : rows) { System.out.print(columns); } System.out.println(""); }
Similar Threads
-
Help with dox matrix printer
By Albert in forum Advanced JavaReplies: 7Last Post: 09-06-2011, 08:50 AM -
[SOLVED] Help with Matrix
By Bernard Robitaille in forum JCreatorReplies: 10Last Post: 02-14-2009, 02:19 AM -
Matrix variations with repetition
By jnovice in forum New To JavaReplies: 4Last Post: 01-19-2009, 08:42 AM -
Displaying Data
By skiing in forum New To JavaReplies: 4Last Post: 11-15-2008, 02:56 AM -
Help with matrix
By susan in forum New To JavaReplies: 1Last Post: 08-07-2007, 04:37 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks