+ 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?
4 ответов
+ 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.
+ 3
Full solution:
https://code.sololearn.com/cKlQwoPAPZWl/#java
@CipherFox was right about using a nested loop.