deyanivanov966

05. Divide Without Remainder

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