Problem when printing the contents of a vector

1

How to make a punctuation store for each answer.

package modulo02;

import java.util.Scanner;

public class vetorGabarito {
    public static void main(String[] args) {
        int pontuacao = 0, n, i, j = 0;
        float s = 0, maiorMedia = -1;
        Scanner sc = new Scanner(System.in);

        System.out.println("Quantos alunos há na turma?: ");
        n = sc.nextInt();

        String nome[] = new String[n];
        char resposta[][] = new char[n][3];
        float media[] = new float[n];
        char gabarito[] = new char[3];

        for (int g = 0; g < gabarito.length; g++) {
            System.out.println("Gabarito questão[" + g + "]: ");
            gabarito[g] = sc.next().charAt(0);
        }

        for (i = 0; i < n; i++) {
            System.out.println("Nome do aluno: ");
            nome[i] = sc.next();



            for (j = 0; j < 3; j++) {
                System.out.println("Resposta nº " + (j + 1));
                resposta[i][j] = sc.next().charAt(0);


                if (resposta[i][j] == gabarito[j]) {

                    pontuacao++;
                }


            }

            System.out.println("Pontuação: " + pontuacao);


        }

        System.out.println("Relatório geral: ");
        System.out.println("resposta - aluno");


        for (i = 0; i < n; i++) {
            System.out.print(nome[i]);



        }

        for (j = 0; j < n; j++) {
            System.out.println(resposta[j]);




            }




    }
}

I wanted the names to be under Students and the answers under Answers.

    
asked by anonymous 16.02.2016 / 19:55

1 answer

2

EDIT: Both char[] x = new char[n] , and char x[] = new char[n] are compiled normally, as @Diego Felipe said. However, it is preferable that the second form be avoided, according to the official documentation ( link ).

Doubt 1:

You already have a q variable that represents all the response sets within that for loop, so you could use this to make an array, that is, a vector of vectors, for your respostaVetor which would look like this:

char[][] respostaVetor = new char[n][10];

So when it comes to saving the answers, you just need to do:

respostaVetor[q][i] = sc.next().charAt(0);

Then, to read, a similar loop, which accesses the group of responses of a student and then the response itself:

System.out.println("\nResposta nº" + q + " \nQuestão[" + i + "]: " + respostaVetor[q][i]);

Doubt 2:

To save each student's score individually, you would only need one more% vector of% s, something like

int[] pontuacao = new int[n];
    
16.02.2016 / 23:54