How to update an array automatically | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to update an array automatically

Hey I was making a program relating to matrices, I was taking the number of rows the person want in the rows, the more the number of rows more the number of numbers inside the matrix, so I did: for(int i=1;i<=rows,i++){ System.out.println("Enter number"); int n=sc.nextInt(); int[] numberrows={number}; } I want to store all the numbers the user enters in the numberrows array. Anyway to do this?

14th Apr 2018, 11:55 AM
divyam sureka
divyam sureka - avatar
2 Answers
+ 12
If the array is multidimensional, you can achieve this with a nested for-loop. One for-loop to address each row, and one to update each element in the row.
14th Apr 2018, 12:24 PM
Fox
Fox - avatar
+ 3
Full solution: https://code.sololearn.com/cKlQwoPAPZWl/#java @CipherFox was right about using a nested loop.
14th Apr 2018, 12:41 PM
Emma