If the intention is to manually populate the matrix, as said in the comments, just change the line within the inner is, making the matrix receive the desired data. The for external control the change of matrix lines, and the for internal controls the change of columns in each row.
In the code below, it would be necessary to enter the 100 positions via user input:
import java.util.Scanner;
public class t151 {
static final int n = 10;
public static void main (String[] args){
Scanner sc = new Scanner(System.in);
int A[][] = new int [n][n];
int i,j;
//este laço controla a mudança de linhas da matriz
for (i=0; i < n; i++){
//já este laço controla
// a mudança de colunas em cada linha da matriz
for (j=0; j < n; j++){
A[i][j] = sc.nextInt();
}
}
}
}
If to fill in with some other value, which does not come from a user input, just remove the sc.nextInt()
and put the data that will be stored.
See the example working on IDEONE.
Can you explain better what you intend to do? At least for me it was not very clear.
– user28595
Actually an array of integers(primitive) is started with all positions at 0. And in the other question you said you wanted to know the cause of the error
ArrayIndexOfBoundException
only. To work with each matrix position, simply change the line of theSystem.out.println
with whatever each position receives. Gives an edited in the text, explaining better what you want to do so facilitates to elaborate a response.– user28595
from what I understand the code is only generating the positions of the matrix, so much so that its output by Meno here is being: 000000000000000000000000000000000000000000000000000000000000 000000000000000000000000 I would like to know how I would manually put the values of each position (of each element) as user input (typing each element) or how I would adjust in the code a random sequence, for example, that measures an output like this: 1234567 etc.
– Leko
I can do this for vectors but I can’t for matrix
– Leko
See my previous comment(if it does not appear full, update this page).
– user28595
edited the question.
– Leko