Wednesday, April 6, 2016

URI 1064 solution in java language


URI Online Judge | 1064

Positives and Average

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Read 6 values that can be floating point numbers. After, print how many of them were positive. In the next line, print the average of all positive values typed, with one digit after the decimal point.

Input

The input consist in 6 numbers that can be integer or floating point values. At least one number will be positive.

Output

The first output value is the amount of positive numbers. The next line should show the average of the positive values ​typed.
Input SampleOutput Sample
7
-5
6
-3.4
4.6
12
4 valores positivos
7.4

URI 1064 solution in java language:

  1. import java.util.Scanner;

  2. public class URI_1064 {

  3. public static void main(String[] args) {
  4. float n1,total = 0,average = 0;
  5. int totalNumber = 0;
  6. Scanner sc =new Scanner(System.in);
  7. for (int i = 1; i <= 6; i++) {
  8. n1 =sc.nextFloat();
  9. if (n1 > 0) {
  10. totalNumber += 1;
  11. total += n1;
  12. }
  13. }
  14. average = total / totalNumber;
  15. System.out.print(totalNumber+" valores positivos\n");
  16. System.out.printf("%.1f\n",average);
  17. }

  18. }






No comments:
Write comments

To know more about the problem, give us your valuable commment. We'll try to help you. Thanks

All rights reserved ©2016 -URI ONLINE JUDGE SOLUTION | Developed by Maniruzzaman Akash

© 2016 URI ONLINE JUDGE SOLUTION. Developed by Maniruzzaman Akash | Distributed By Gooyaabi Templates
Powered by Blogger.