java easy array explain | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

java easy array explain

explain it line by line please int[][] array = new int[5][6]; int[] x = {1, 2}; array[0] = x; System.out.println("array[0][1] is " + array[0][1]);

26th Oct 2021, 4:00 AM
STOP
STOP - avatar
4 Answers
+ 2
You're dealing with a two-dimensional array. Lesson 24.1 of the java course explains how they work.
26th Oct 2021, 4:32 AM
Simon Sauter
Simon Sauter - avatar
+ 2
- create empty array[5] of empty arrays[6] of int 5,6 are length, int is integer, number, name of array is 'array' - create array named x with two elements 1,2 - add x array to 'array' at position [0] it is possible because 'array' elements are another array - print values on screen: . "array[0][1] is " is information for user, its String of characters . + join also to message: . array in position 0 is x array and its element at position 1 is 2
26th Oct 2021, 4:46 AM
zemiak
+ 1
https://www.geeksforgeeks.org/introduction-to-arrays/amp/ https://www.geeksforgeeks.org/array-data-structure/ Hope this link helps you to know it in detail. Because sometimes it is difficult to write and explain
26th Oct 2021, 4:18 AM
Atul [Inactive]
0
Line 1) Creates an array of two dimensions (an array of arrays) where the first array has 5 elements, and each of those elements is an array of 6 elements. Every value is initialized to 0 by default in the array. So for instance, the first and second elements of the outer array is {0,0,0,0,0,0}, {0,0,0,0,0,0} Line 2) Creates an array x that contains two elements of values 1 and 2. Its important to note that the indexes for these values are 0 and 1, so x[0] = 1 and x[1] = 2 Line 3) Assigns the first element (and first array) of array[] as a reference to x[]. Whereas in line 1, array[0] = {0,0,0,0,0,0} ; now array[0] = {1,2}. The rest of the elements fir array[] remain the same, only the first element was changed to point at a different set of values. Line 4) Prints the string inside the quotes , and appends (using the + to append) the value at array[0][1]. array[] is still a two dimensional array, so the first bracket [0] points to the first element {1,2} and [1] points to 2.
27th Oct 2021, 7:36 AM
Emiliano Rodriguez
Emiliano Rodriguez - avatar