Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- int gameMoves = Integer.parseInt(input.nextLine());
- double from0to9 = 0;
- double from10to19 = 0;
- double from20to29 = 0;
- double from30to39 = 0;
- double from40to50 = 0;
- double invalidNumbers = 0;
- double totalResult = 0;
- for (int i = 0; i < gameMoves; i++) {
- int checkNumber = Integer.parseInt(input.nextLine());
- if (checkNumber >= 0 && checkNumber <= 9) {
- from0to9++;
- totalResult += checkNumber * 0.2;
- } else if (checkNumber >= 10 && checkNumber <= 19) {
- from10to19++;
- totalResult += checkNumber * 0.3;
- } else if (checkNumber >= 20 && checkNumber <= 29) {
- from20to29++;
- totalResult += checkNumber * 0.4;
- } else if (checkNumber >= 30 && checkNumber <= 39) {
- from30to39++;
- totalResult += 50;
- } else if (checkNumber >= 40 && checkNumber <= 50) {
- from40to50++;
- totalResult += 100;
- } else {
- totalResult /= 2;
- invalidNumbers++;
- }
- }
- System.out.printf("%.2f%n", totalResult);
- System.out.printf("From 0 to 9: %.2f%%%n", from0to9 / gameMoves * 100);
- System.out.printf("From 10 to 19: %.2f%%%n",from10to19 / gameMoves * 100);
- System.out.printf("From 20 to 29: %.2f%%%n",from20to29 / gameMoves * 100);
- System.out.printf("From 30 to 39: %.2f%%%n",from30to39 / gameMoves * 100);
- System.out.printf("From 40 to 50: %.2f%%%n",from40to50 / gameMoves * 100);
- System.out.printf("Invalid numbers: %.2f%%%n",invalidNumbers / gameMoves * 100);
- }
- }
Add Comment
Please, Sign In to add comment