skipter

Division without residue - 26 March 2016 - Java Basics

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