Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int n = Integer.parseInt(scanner.nextLine());
  7.         double p1 = 0;
  8.         double p2 = 0;
  9.         double p3 = 0;
  10.         for (int i = 1; i <= n; i++) {
  11.             int num = Integer.parseInt(scanner.nextLine());
  12.             if (num % 2 == 0) {
  13.                 p1++;
  14.             }
  15.             if (num % 3 == 0) {
  16.                 p2++;
  17.             }
  18.             if (num % 4 == 0) {
  19.                 p3++;
  20.             }
  21.         }
  22.         double p1Perc = p1 / n * 100;
  23.         double p2Perc = p2 / n * 100;
  24.         double p3Perc = p3 / n * 100;
  25.         System.out.printf("%.2f%%%n", p1Perc);
  26.         System.out.printf("%.2f%%%n", p2Perc);
  27.         System.out.printf("%.2f%%%n", p3Perc);
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement