Add values in a 3-dimensional matrix

Asked

Viewed 55 times

-1

How do I get the user to add values to an array [][][]?

calendarioEventos = new Evento[dia][mes][hora];
    for(int i = 0; i < calendarioEventos.length; i++) {
        for(int j = 0; j < calendarioEventos[i].length; j++) {
            for(int k = 0; k < calendarioEventos[i][j].length; k++) {
                this.calendarioEventos[i][j][k] = new Evento();

I have this matrix of an event calendar where the user has to add an event to a time of day. How do I do this?

  • Pass the positions and be happy, now, select your code to get a closer response to your reality?

  • Hello, could you mark the answer as correct? Thank you!

1 answer

2

Scanner input = new Scanner(System.in);
int[][][] matriz = new int[2][2][2];
for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
        for (int k = 0; k < 2; k++) {
            System.out.println("Digite o valor para Matriz[" + i + "][" + j + "][" + k + "]");
            int val = Integer.parseInt(input.nextLine());
            matriz[i][j][k] = val;
        }
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.