+ 6

How one can fill a multidimensional array in Java?

Could you please suggest any proper way of filling a multidimensional array with random numbers in Java? I am particularly interested in those using for loops.

17th Feb 2019, 10:37 AM
ZdzichPych
ZdzichPych - avatar
6 odpowiedzi
+ 7
My example with 2D array filled with random numbers between 0 and 10. Hope it helps you. https://code.sololearn.com/cx6oKVOQW37z/?ref=app
17th Feb 2019, 11:22 AM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 3
Thank you very much for your answer! It is very helpful!
17th Feb 2019, 1:57 PM
ZdzichPych
ZdzichPych - avatar
+ 2
You are welcome 😉
17th Feb 2019, 2:17 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 2
JAVA Multidimensional Arrays Multidimensional arrays are array that contain other arrays. The two-dimensional array is the most basic multidimensional array. To create multidimensional arrays, place each array within its own set of square brackets. Example of a two-dimensional array: int[ ][ ] sample = { {1, 2, 3}, {4, 5, 6} }; This declares an array with two arrays as its elements. To access an element in the two-dimensional array, provide two indexes, one for the array, and another for the element inside that array. The following example accesses the first element in the second array of sample. int x = sample[1][0]; System.out.println(x); // Outputs 4 The array's two indexes are called row index and column index. Multidimensional Arrays You can get and set a multidimensional array's elements using the same pair of square brackets. Example: int[ ][ ] myArr = { {1, 2, 3}, {4}, {5, 6, 7} }; myArr[0][2] = 42; int x = myArr[1][0]; // 4 The above two-dimensional array contains three arrays.
27th Feb 2019, 3:32 AM
Lloyd L Conley
Lloyd L Conley - avatar
+ 2
The easiest way is to use nested for loops.
12th Mar 2019, 3:04 PM
jookspa
jookspa - avatar
+ 2
Multiple Arrays are very useful for statistical and electrical engineering work. I have written APPS for addition, subtraction and multiplication on N x M matrix. I wrote in user friendly Visual Basic using Microsoft Visual Studios 10.
12th Mar 2019, 3:15 PM
Lloyd L Conley
Lloyd L Conley - avatar