Advertisement
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 scanner = new Scanner(System.in);
- int quantity = Integer.parseInt(scanner.nextLine()),
- red = 0, orange = 0, blue = 0, green = 0, maxCount = 0;
- String color, maxColor = "";
- for (int i = 0; i < quantity; i++) {
- color = scanner.nextLine();
- switch (color) {
- case "red" -> red++;
- case "orange" -> orange++;
- case "blue" -> blue++;
- case "green" -> green++;
- }
- }
- if (red > orange && red > blue && red > green) {
- maxCount = red;
- maxColor = "red";
- } else if (orange > blue && orange > green && orange > red) {
- maxCount = orange;
- maxColor = "orange";
- } else if (blue > green && blue > red && blue > orange) {
- maxCount = blue;
- maxColor = "blue";
- } else {
- maxCount = green;
- maxColor = "green";
- }
- System.out.printf(
- """
- Red eggs: %d
- Orange eggs: %d
- Blue eggs: %d
- Green eggs: %d
- Max eggs: %d -> %s
- """, red, orange, blue, green, maxCount, maxColor);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement