(URI) Positivos e Média - Solução

import java.io.*;
import java.util.*;
import java.lang.*;

class Main  {
    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
       
        final int QTE = 6;
       
        double soma = 0;
        int contador = 0;
        for (int i = 0; i < QTE; i++) {
            Double d = Double.parseDouble(br.readLine());
            if (d > 0) {
                soma += d;
                contador++;
            }
        }
        System.out.println(contador + " valores positivos");
        System.out.printf("%.1f", soma/contador);
        System.out.println();
    }
}

Comments

Popular posts from this blog

(Coderbyte) Dash Insert II - Solução

(Coderbyte) Run Length - Solução

(Coderbyte) Counting Minutes I - Solução