I didn't understand pff plz someone explain to me how this arrays work | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I didn't understand pff plz someone explain to me how this arrays work

27th Feb 2017, 8:12 PM
Yassir- Alkhatib
Yassir- Alkhatib - avatar
4 Answers
+ 1
Array is collection of data of same type. That is placed under one common name. Accessed with indexing beginning from 0. Array is used so that related data can be stored at contiguous memory locations, unlike normal variable, which are stored any where they find place for their size. But for example u created an array of 10 integers which will take 40 bytes (10 elements * 4 bytes each element) will be stored in memory wherever it finds the empty 40 bytes for it. Array is created as: datatype[] name= new datatype[size] ;
27th Feb 2017, 8:22 PM
Divesh Agarwal
Divesh Agarwal - avatar
+ 1
The first bracket is the array "number" if you will. The next bracket is the index.
27th Feb 2017, 10:27 PM
NickB
NickB - avatar
0
public class Program { public static void main(String[] args) { int[ ][ ] sample = { {1, 2, 3}, {4, 5, 6} }; int x = sample[1][0]; System.out.println(x); } } can you explain to me why outputs it's 4
27th Feb 2017, 8:31 PM
Yassir- Alkhatib
Yassir- Alkhatib - avatar
0
thnk you sooo much guys
28th Feb 2017, 10:12 AM
Yassir- Alkhatib
Yassir- Alkhatib - avatar