Advertisement
totopopov

Game Of Intervals

Jul 20th, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.95 KB | None | 0 0
  1. package lastMeeting;
  2.  
  3. import java.util.Scanner;
  4.  
  5. /**
  6.  * Created by Todor Popov using Lenovo on 20.7.2017 г. at 11:17.
  7.  */
  8. public class GameInInterval {
  9.     public static void main(String[] args) {
  10.  
  11.         Scanner scaner = new Scanner(System.in);
  12.  
  13.         int count = Integer.parseInt(scaner.nextLine());
  14.  
  15.         double points = 0;
  16.  
  17.         double count9 = 0;
  18.         double count19 = 0;
  19.         double count29 = 0;
  20.         double count39 = 0;
  21.         double count50 = 0;
  22.         double invalid = 0;
  23.  
  24.         for (int i = 0; i < count; i++) {
  25.  
  26.             int currentNumber = Integer.parseInt(scaner.nextLine());
  27.  
  28.             if (currentNumber >= 0) {
  29.                 if (currentNumber <= 9) {
  30.                     points += currentNumber * 0.2;
  31.                     count9++;
  32.                 } else if (currentNumber <= 19) {
  33.                     points += currentNumber * 0.3;
  34.                     count19++;
  35.                 } else if (currentNumber <= 29) {
  36.                     points += currentNumber * 0.4;
  37.                     count29++;
  38.                 } else if (currentNumber <= 39) {
  39.                     points += 50;
  40.                     count39++;
  41.                 } else if (currentNumber <= 50) {
  42.                     points += 100;
  43.                     count50++;
  44.                 }
  45.             }
  46.  
  47.             if (currentNumber < 0 || currentNumber > 50) {
  48.                 points = points / 2;
  49.                 invalid++;
  50.             }
  51.  
  52.         }
  53.         System.out.printf("%.2f%n",points);
  54.         System.out.printf("From 0 to 9: %.2f%%%n",count9/count*100);
  55.         System.out.printf("From 10 to 19: %.2f%%%n",count19/count*100);
  56.         System.out.printf("From 20 to 29: %.2f%%%n",count29/count*100);
  57.         System.out.printf("From 30 to 39: %.2f%%%n",count39/count*100);
  58.         System.out.printf("From 40 to 50: %.2f%%%n",count50/count*100);
  59.         System.out.printf("Invalid numbers: %.2f%%%n",invalid/count*100);
  60.     }
  61.  
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement