Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class nested {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- int redCount = 0;
- int orangeCount = 0;
- int blueCount = 0;
- int greenCount = 0;
- int max = Integer.MIN_VALUE;
- double proba = 0.0;
- String maxEggs = "";
- for (int i = 1; i <= n; i++) {
- String color = scanner.nextLine();
- if (color.equals("red")){
- redCount++;
- if (redCount>max){
- max = redCount;
- maxEggs="red";
- }
- } else if (color.equals("orange")){
- orangeCount++;
- if (redCount>max){
- max = orangeCount;
- maxEggs="orange";
- }
- } else if (color.equals("blue")){
- blueCount++;
- if (redCount>max){
- max = blueCount;
- maxEggs="blue";
- }
- } else if (color.equals("green")){
- greenCount++;
- if (redCount>max){
- max = greenCount;
- maxEggs="green";
- }
- }
- }
- System.out.printf("Red eggs: %d%n", redCount);
- System.out.printf("Orange eggs: %d%n", orangeCount);
- System.out.printf("Blue eggs: %d%n", blueCount);
- System.out.printf("Green eggs: %d%n", greenCount);
- System.out.printf("Max eggs: %d -> %s",max,maxEggs);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement