Advertisement
Spocoman

Balls

Sep 1st, 2024
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.55 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int balls = Integer.parseInt((scanner.nextLine())),
  7.                 red = 0, orange = 0, yellow = 0, white = 0,
  8.                 black = 0, other = 0, totalPoints = 0;
  9.         String color;
  10.        
  11.         for (int i = 0; i < balls; i++) {
  12.             color = scanner.nextLine();
  13.             switch (color) {
  14.                 case "red" -> {
  15.                     totalPoints += 5;
  16.                     red++;
  17.                 }
  18.                 case "orange" -> {
  19.                     totalPoints += 10;
  20.                     orange++;
  21.                 }
  22.                 case "yellow" -> {
  23.                     totalPoints += 15;
  24.                     yellow++;
  25.                 }
  26.                 case "white" -> {
  27.                     totalPoints += 20;
  28.                     white++;
  29.                 }
  30.                 case "black" -> {
  31.                     totalPoints /= 2;
  32.                     black++;
  33.                 }
  34.                 default -> other++;
  35.             }
  36.         }
  37.  
  38.         System.out.printf("Total points: %d\n", totalPoints);
  39.         System.out.printf("Red balls: %d\n", red);
  40.         System.out.printf("Orange balls: %d\n", orange);
  41.         System.out.printf("Yellow balls: %d\n", yellow);
  42.         System.out.printf("White balls: %d\n", white);
  43.         System.out.printf("Other colors picked: %d\n", other);
  44.         System.out.printf("Divides from black balls: %d\n", black);
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement