5
public class VetorTurma {
public static void main(String[] args) {
int pontuacao = 0,nota,c;
String nome;
Scanner sc = new Scanner(System.in);
double gabaritoVetor[] = new double[10];
double notaVetor[] = new double[10];
System.out.println("Digite o gabarito: ");
for(c=0;c < gabaritoVetor.length;c++){
System.out.print("Gabarito | questão["+c+"]: ");
gabaritoVetor[c]=sc.nextDouble();
}
int i = 0;
for(i=0;i < notaVetor.length;i++){
System.out.print("Questão["+i+"]: ");
notaVetor[i] = sc.nextDouble();
}
if(gabaritoVetor==notaVetor){
pontuacao ++;
}
System.out.println("Pontuação: "+pontuacao);
}
}
The if counter always returns zero. What must be wrong?
NOTE: It may seem strange numbers as feedback the right would be a,b,c,d. But first I want to do with numbers and then as characters.
Do you want to compare the values of both vectors? The way you are doing, if compares whether the reference to the two vector objects is the same, which is false. You need to do a for to rotate over the first vector and another for internal to compare all the indices of the second as the first for will iterate the indices of the first vector.
– user28595
Yes, in vector case A[0]: 2 | vector B[0]: 2. if(vector A==vector B) C++. This is the idea.
– Marcelo T. Cortes