fork download
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7.  
  8. import java.util.Scanner;
  9. import java.io.IOException;
  10. /**
  11.  *
  12.  * @author kOgY
  13.  */
  14. public class Main {
  15.  
  16. /**
  17.   * @param args the command line arguments
  18.   * @throws java.io.IOException
  19.   */
  20. public static void main(String[] args) throws IOException{
  21. float num;
  22. int count=0;
  23. float average=0;
  24. try (Scanner input = new Scanner(System.in)) {
  25. while(input.hasNext()){
  26. num = input.nextFloat();
  27. if(num>0){
  28. count++;
  29. average+=num;
  30. }
  31. }
  32. }
  33. System.out.printf("%d valores positivos\n", count);
  34. System.out.printf("%.1f\n", average/count);
  35. }
  36.  
  37. }
Success #stdin #stdout 0.12s 380736KB
stdin
7
-5
6
-3.4
4.6
12
stdout
4 valores positivos
7.4