Approvals, reprovacations and room-Java media

Asked

Viewed 60 times

0

I need to receive 30 bills and return the number of approvals, reprobations and the average of the room. I tried the following:

public class notas { 
public static int aprovacoes;
public static int reprovacoes;
public static int recs;
public static double total;

public static void main(String []args){
    double notas[] = new double [30];

    Scanner input = new Scanner(System.in);
    System.out.print("Digite todas as notas: ");
    for(int i = 0; i < notas.length; i++){
        notas[i] = input.nextDouble();
    }
    System.out.println("numero de aprovados: "+aprovacoes);
    System.out.println("numero de reprovados: "+reprovacoes);
    System.out.println("numero de recs: "+recs);
    System.out.println("media da sala: "+(total/30));
}
    public static void resultadoSala(double [] notas){
        for(int i = 0; i < notas.length; i++){
            if(notas[i] >= 5){
                aprovacoes++;
            }
            else if(notas[i] <= 3){
                reprovacoes++;
            }
            else{
                recs++;
            }
        }
    }
    public static double mediaSala(double []notas){
        for(int i = 0; i < notas.length; i++){
            total += notas[i];  
        }
        return total;
    }

}

However, after compiling the code and inserting the notes, all outputs were zero. What I must do?

1 answer

1

It was missing to call the methods resultadoSala and mediaSala:

public static void main(String []args){
    double notas[] = new double [30];

    Scanner input = new Scanner(System.in);
    System.out.print("Digite todas as notas: ");
    for(int i = 0; i < notas.length; i++){
        notas[i] = input.nextDouble();
    }

    resultadoSala(notas);
    mediaSala(notas);

    System.out.println("numero de aprovados: "+aprovacoes);
    System.out.println("numero de reprovados: "+reprovacoes);
    System.out.println("numero de recs: "+recs);
    System.out.println("media da sala: "+(total/30));
}

Browser other questions tagged

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