English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I'm writing a method to clear a 2D array of booleans. So if I have an array called test[9][3], I know that test.length would be 9. But how do I access the 3?

2007-11-25 01:37:54 · 4 answers · asked by stopthemadness 1 in Computers & Internet Programming & Design

4 answers

test[1].length == 3

You can view 2d array as an array of arrays, which means that it is one dimensional array where elements are arrays. So when you call "test[1]" it returns the reference to the array which has index 1 as an element, so its length will be 3

2007-11-25 01:46:07 · answer #1 · answered by Berkut 2 · 0 0

Access the 3?
You have made an array of 9 rows across and 3 col. Correct? Starting each at 0
so thats like:
1 2 3
4 5 6
7 8 9
a b c
d e f
g h i
m n o
p q r
s t u

To access any part use the row, col
test[7][2] would give you r

And you always need a double for loop to move around them, the outter loop being the row (goes 9x), the inner being the col (goes 3x).

Not sure if I answered you....

2007-11-25 03:05:32 · answer #2 · answered by ? 6 · 1 0

I think this is something like you are looking for. But I don't understand what you mean by "check if numbers are the same," or how you want to loop through there. If you want to personally contact me, i'd be glad to try and help. for (int i = 0; i < array.length; i++) { for (int j = i + 1; j < array.length; j++) { if (array[i] == array[j]) { ... do something } } }

2016-04-05 21:27:56 · answer #3 · answered by ? 4 · 0 0

test[0].length

2007-11-25 01:43:12 · answer #4 · answered by AnalProgrammer 7 · 0 0

fedest.com, questions and answers