Advertisement
veronikaaa86

05. Divide Without Remainder

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