Ajuda com média aritmética

1 resposta
java
D

Gente estou com problemas em fazer da certo a média aritmética, fiz de vários jeitos e esse foi o mais erado q fiz! alguém pode me ajudar sem usar o float?

public class Aluno extends Pessoa {

private double[] notas;

private double mediaAritmetica;
public Aluno (int n, String nom){
    super(n,nom);
    this.notas = new double[6];
    this.mediaAritmetica = 0.0;
}

public int menorIndice() {
double menor = 0;
int indice = -1;
for (int i = 0; i < notas.length; i++){
    if (notas[i]  > menor) {
       menor = notas[i];
       indice = i;
    }
}
return indice;

}

public void registraNota (int qual, double nota){
    if (qual >=1 && qual <=6) {
        notas[qual] = nota;
    }
}
public void calculaMediaAritmetica() {
      int media = 0;
    for(int i = 0; i<notas.length; i++){
        media += notas[i];

    float total = (float)media /  notas.length;
    
}

}
}

1 Resposta

M
public void calculaMediaAritmetica() {

double media = 0;

for(int i = 0; i<notas.length; i++){

media += notas[i];
double total = media / notas.length;

}

Criado 25 de novembro de 2018
Ultima resposta 26 de nov. de 2018
Respostas 1
Participantes 2