Advertisement
Spocoman

Easter Eggs

Sep 4th, 2024
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.41 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 quantity = Integer.parseInt(scanner.nextLine()),
  7.                 red = 0, orange = 0, blue = 0, green = 0, maxCount = 0;
  8.         String color, maxColor = "";
  9.  
  10.         for (int i = 0; i < quantity; i++) {
  11.             color = scanner.nextLine();
  12.             switch (color) {
  13.                 case "red" -> red++;
  14.                 case "orange" -> orange++;
  15.                 case "blue" -> blue++;
  16.                 case "green" -> green++;
  17.             }
  18.         }
  19.  
  20.         if (red > orange && red > blue && red > green) {
  21.             maxCount = red;
  22.             maxColor = "red";
  23.         } else if (orange > blue && orange > green && orange > red) {
  24.             maxCount = orange;
  25.             maxColor = "orange";
  26.         } else if (blue > green && blue > red && blue > orange) {
  27.             maxCount = blue;
  28.             maxColor = "blue";
  29.         } else {
  30.             maxCount = green;
  31.             maxColor = "green";
  32.         }
  33.  
  34.         System.out.printf(
  35.                 """
  36.                        Red eggs: %d
  37.                        Orange eggs: %d
  38.                        Blue eggs: %d
  39.                        Green eggs: %d
  40.                        Max eggs: %d -> %s
  41.                        """, red, orange, blue, green, maxCount, maxColor);
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement