Advertisement
yovkovbpfps

For Loop Exercise Divide Without Reminder

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