Results 1 to 6 of 6
Thread: Array question
- 06-09-2010, 12:43 PM #1
- 06-09-2010, 12:57 PM #2
2 rows and 3 column. myArray[1][1] would give you the same answer regardless if it's 3 column & 2 rows or 3 rows & 2 columns: 5
Let's say you did:
you would get: 4Java Code:int myAnswer = myArray[1][0]
"Experience is what you get when you don't get what you want" (Dan Stanford)
"Rise and rise again until lambs become lions" (Robin Hood)
- 06-09-2010, 01:05 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
Java is (just as all C-like languages) row oriented w.r.t. arrays. Try it:
AFAIK only Fortran stores its matrixes in a column oriented way ...Java Code:int[][] myArray= { { 1, 2, 3 }, { 4, 5, 6 } }; printRow(myArray[0]); printRow(myArray[1]); ... private static void printRow(int[] row) { System.out.println(Arrays.toString(row)); }
kind regards,
Jos
- 06-09-2010, 01:05 PM #4
look at the following code
Java Code:public class ArrayOutput { public static void main(String[] args) { int[][] myArray = { { 1, 2, 3 }, { 4, 5, 6 } }; for (int i = 0; i < myArray.length; i++) { for (int j = 0; j < myArray[i].length; j++) System.out.println("Array[" + i + "][" + j + "] = " + myArray[i][j]); } } }
that will output each element in the array
Array[0][0] = 1
Array[0][1] = 2
Array[0][2] = 3
Array[1][0] = 4
Array[1][1] = 5
Array[1][2] = 6
now, are you able to guess the output of this array?
int[][] myArray = { { 1 }, { 4, 5, 6 }, {2, 3}};Last edited by j2me64; 06-09-2010 at 01:08 PM.
- 06-10-2010, 09:41 PM #5
Thanks everyone.
- 06-11-2010, 01:41 AM #6
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
Similar Threads
-
Array Question
By sc001 in forum New To JavaReplies: 1Last Post: 02-14-2010, 04:57 AM -
need help with question(method & array)
By highschool in forum New To JavaReplies: 5Last Post: 02-10-2010, 05:06 PM -
array question
By dazednconfused in forum New To JavaReplies: 4Last Post: 09-15-2009, 05:44 AM -
Array question
By McChill in forum New To JavaReplies: 5Last Post: 02-20-2009, 02:18 AM -
Basic array question
By jigglywiggly in forum New To JavaReplies: 12Last Post: 01-09-2009, 04:44 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks