List of number arrays

  • 6
  • Locked
By Level 9, students are already adept at manipulating arrays and they know a thing or two about lists. Let's unify this knowledge by trying the following task. We'll create a list whose elements are arrays of numbers. Then we'll add to the list five array objects whose lengths are 5, 2, 4, 7, and 0, respectively. Finally, we'll fill the arrays with any data and display them on the screen.
You can't complete this task, because you're not signed in.
Comments (4)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Lucas Hoage
Level 14 , Savannah, United States
6 June 2020, 03:18
Okay so I did one of the tasks of filling data into each array with any data by creating a for loop with each number entered as the iterator ith value. This was done for each int[] array prior to adding it into the ArrayList. Is there a better way to do this? LIke with nested for loops after the ArrayList is propogated? A way that doesn't throw an OOB? I know if I had a multidimensional array, I could run through the matrix that way, is the same possible with an ArrayList of array types? Would it be something like: (Example shortened for all our sake)
for i; i < List.size;i++
    for j; j < a.get(0).length;j++
         for k; k < a.get(1).length; k++
Is something like that possible? Also, how would I add data into each int[] array while inside the ArrayList nested loop? Even outside of a nested scenario, how DO I add data into an array[] inside an ArrayList?
Lucas Hoage
Level 14 , Savannah, United States
6 June 2020, 03:19
To add to this. I do understand using .set for an ArrayList, I'm just unsure of how to target the array indexes inside the ArrayList indexes I should further clarify I don't mean pre populating the data using the standard: { "1", "2", "3", "4" }; Method upon initializing them. I'm referring specifically to modifying the data while it's stuck inside a nested or non nested for loop.
Mike McKenna
Level 25 , Wilmington, United States
16 December 2019, 01:53
read task requirements carefully . do not put any matching numbers in arrays . always check the math !!
Level 24 , Budapest, Hungary
30 May 2019, 16:09
Am I the only one, who thought about Euclidean norm at the array length? :D