0
The variables media and contador, after the execution, they print many times and I don’t understand why. I wanted them to print only once at the end of the execution of the whole code.
My code:
import java.util.Scanner;
public class Chuva{
    public static void main(String[] args){
        int chuvadia;
        int [] chuva;
        int semanal;
        int quantidade;
        int y = 0;
        int i;
        double media;
        int soma = 0;
        int contador =0;
        double perc;
        Scanner input = new Scanner(System.in);
        //REGISTAR A QUANTIDADE DE CHUVA
        System.out.println("Insira a quantidade de chuva total esta semana");
        semanal = input.nextInt();
        //
        chuva = new int[7];
        if(semanal < 0){
            System.out.println("A quantidade de chuva nao pode ser negativa");
        } else {
        for(i = 0; i<chuva.length; i++){
                System.out.println("Indique a quantidade de chuva no dia" + y);
                y++;
                chuvadia = input.nextInt();
                if(chuvadia < 0){
                    System.out.println("A chuva nao pose ser negativa");
                    break;
                } else {
                chuva[i] = chuvadia;
                }
        }
        for(i = 0; i<chuva.length; i++){
            soma+= chuva[i];
        }
        media = (soma/7);
        System.out.println("A media e de:" + media);
        for(i=0;i<chuva.length;i++){
            double max = chuva[0];
            if( chuva[i] > max){
                max = chuva[i];
                System.out.println("O maior e:" + max);
            }
        }
        }
        for(i=0;i<chuva.length;i++){
            perc = (chuva[i]/semanal);
            if(perc < 0.2){
                contador++;
            }
            System.out.println("O n de dias com perc de chuva menor que 20% da semanal e:" + contador);
        }
}
}
Ué, the
System.out.printlnis inside afor, there appears several times even– Sorack
That’s it, thank you! Now I have another error, when running it is not giving the correct maximum here: for(i=0;i<rain.length;i++){ double max = rain[0]; if( rain[i] > max){ max = rain[i]; System.out.println("The biggest and:" + max); } Know why?
– Fabio Ribeiro