Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class GameOfIntervals {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- int num0To10 = 0;
- int num10To20 = 0;
- int num20To30 = 0;
- int num30To40 = 0;
- int num40To50 = 0;
- int invalidNum = 0;
- double result = 0;
- for (int i = 0; i < n; i++) {
- double number = Double.parseDouble(scanner.nextLine());
- if (number >= 0 && number < 10) {
- result += number * 0.2;
- num0To10++;
- } else if (number >= 10 && number < 20) {
- result += number * 0.3;
- num10To20++;
- } else if (number >= 20 && number < 30) {
- result += number * 0.4;
- num20To30++;
- } else if (number >= 30 && number < 40) {
- result += 50;
- num30To40++;
- } else if (number >= 40 && number <= 50) {
- result += 100;
- num40To50++;
- } else{
- result /= 2;
- invalidNum++;
- }
- }
- System.out.printf("%.2f\n", result);
- System.out.printf("From 0 to 9: %.2f%%\n", (double)num0To10 / n * 100);
- System.out.printf("From 10 to 19: %.2f%%\n", (double)num10To20 / n * 100);
- System.out.printf("From 20 to 29: %.2f%%\n",(double)num20To30 / n * 100);
- System.out.printf("From 30 to 39: %.2f%%\n", (double)num30To40 / n * 100);
- System.out.printf("From 40 to 50: %.2f%%\n", (double)num40To50 / n * 100);
- System.out.printf("Invalid numbers: %.2f%%\n", (double)invalidNum / n * 100);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement