Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //5. Игра на интервали
- public class MyClass {
- public static void main(String args[]) {
- java.util.Scanner scanner = new java.util.Scanner(System.in);
- int turns = scanner.nextInt();
- double finalScore = 0.0;
- int numbersFrom0to9 = 0;
- int numbersFrom10to19 = 0;
- int numbersFrom20to29 = 0;
- int numbersFrom30to39 = 0;
- int numbersFrom40to50 = 0;
- int numbersInvalid = 0;
- int number = 0;
- for (int i = 1; i <= turns; i++) {
- number = scanner.nextInt();
- if (number >= 0 && number <= 9) {
- numbersFrom0to9++;
- finalScore += 0.2 * number;
- }
- else if (number >= 10 && number <= 19) {
- numbersFrom10to19++;
- finalScore += 0.3 * number;
- }
- else if (number >= 20 && number <= 29) {
- numbersFrom20to29++;
- finalScore += 0.4 * number;
- }
- else if (number >= 30 && number <= 39) {
- numbersFrom30to39++;
- finalScore += 50;
- }
- else if (number >= 40 && number <= 50) {
- numbersFrom40to50++;
- finalScore += 100;
- }
- else {
- numbersInvalid++;
- finalScore = finalScore * 0.5;
- }
- }
- System.out.printf("%.2f\n",finalScore);
- System.out.printf("From 0 to 9: %.2f%%\n", (double)numbersFrom0to9/turns * 100);
- System.out.printf("From 10 to 19: %.2f%%\n", (double)numbersFrom10to19/turns * 100);
- System.out.printf("From 20 to 29: %.2f%%\n", (double)numbersFrom20to29/turns * 100);
- System.out.printf("From 30 to 39: %.2f%%\n", (double)numbersFrom30to39/turns * 100);
- System.out.printf("From 40 to 50: %.2f%%\n", (double)numbersFrom40to50/turns * 100);
- System.out.printf("Invalid numbers: %.2f%%\n", (double)numbersInvalid/turns * 100);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement