1

I created a global array:

static String[][] pauta;

Then, I created this method which is going to receive user inputs, and those inputs are going to set the size of the array:

public static void definirTamanhoPauta() {  
    int nAlunos, nTestes;

    nAlunos = teclado.nextInt();
    nTestes = teclado.nextInt();

    pauta = new String[nAlunos][nTestes];
}

(Let's assume the user wanted to create a 2x2 array, so the values of the variables nAlunos and nTestes are both going to be 2)

And then I have another code which intends to fill all the rows of the array 1st column with, once more, user-defined values:

public static void definirNumeroAlunos() {
    for (int i = 0; i < pauta.length; i++) {
        System.out.print("pauta[" + i + "][0] = ");
        pauta[i][0] = teclado.nextLine();
        System.out.println();
    }
}

Except if I have the user define the size of the array, the loop doesn't ask a value for pauta[0][0] and only asks a value for pauta[1][0]

Output:

pauta[0][0] = // skipped
pauta[1][0] = // only there it asks for user input

However, if I set up the array like this:

static String[][] pauta = new String[2][2]

And don't call the definirTamanhoPauta() method, the output of the definirNumeroAlunos() is going to be this:

pauta[0][0] = // doesn't skip this anymore
pauta[1][0] = // asks for user input here, too

What is going on there? I really can't figure it out.

0 Answers0