 Arrays | Sololearn: Learn to code for FREE!

+2

# Arrays

public class Arrays {     public static void main (String [] args)     {          int number [][]={ {3, 5 , 6 ,7, 34}, {9, 22, 25,44,70} };         System.out.println(number);     } } I’ve been trying to understand arrays in java, so far I get the basics. Can someone explain to me why the output of the code pasted above is 5?

+9

consider 3 arrays, a,b and c a = {3, 5,6, 7, 34} b = {9, 22, 25, 44, 70} the 'c' array is: c = {a, b} the expression says: "get the first item of c (a) and from that item get its second element (5)"

+3

This is a two-dimensional array (an array of arrays). So it has two "layers". Layer 1 is an array of size 2. Each element has an array. Index 0(number): {3,5,6,7,34} Index 1(number): {9,22,25,44,70} Layer 2 has two arrays, one for each index of layer 1. Both arrays have 5 integer numbers (indexes 0 to 4). number: 3 number: 5 number: 6 number: 7 number: 34 number: 9 number: 22 and so on... You can make an array with many dimensions, but it is very unlikely that you will need more than 3. An example of a 3D array (an array of 2D arrays): int[][][] my3dArray = { { {8,5,4}, {3,2,9} }, { {2,6}, {9,3}, {2} }, { {}, {0} }, {} } ; number: 8 number: 9 number: 2 number: { {}, {0} } number: 0 number: {} (empty array - size zero) As you can see, any array of any layer can have its own size. Note that trying to access number or number throws an ArrayIndexOutOfBoundsException

+3

It is two dimntional array. so we can write in matrix form as shown below      [ 0] | 3 5 6 7 34 | [ 1] | 9 22 25 44 70 | For number  = 5

+2

I wrote a small code to exemplify my answer: https://code.sololearn.com/ciUy9U0Ihd1j/?ref=app

+2

Helio Oliveira Bianchi thanks alot man

0

For some reason I am having quite a hard time with arrays...😕