Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4. public class nested {
  5. public static void main(String[] args) {
  6. Scanner scanner = new Scanner(System.in);
  7. int n = Integer.parseInt(scanner.nextLine());
  8. int redCount = 0;
  9. int orangeCount = 0;
  10. int blueCount = 0;
  11. int greenCount = 0;
  12. int max = Integer.MIN_VALUE;
  13. double proba = 0.0;
  14. String maxEggs = "";
  15.  
  16. for (int i = 1; i <= n; i++) {
  17. String color = scanner.nextLine();
  18. if (color.equals("red")){
  19. redCount++;
  20. if (redCount>max){
  21. max = redCount;
  22. maxEggs="red";
  23. }
  24. } else if (color.equals("orange")){
  25. orangeCount++;
  26. if (redCount>max){
  27. max = orangeCount;
  28. maxEggs="orange";
  29. }
  30. } else if (color.equals("blue")){
  31. blueCount++;
  32. if (redCount>max){
  33. max = blueCount;
  34. maxEggs="blue";
  35. }
  36. } else if (color.equals("green")){
  37. greenCount++;
  38. if (redCount>max){
  39. max = greenCount;
  40. maxEggs="green";
  41. }
  42. }
  43. }
  44. System.out.printf("Red eggs: %d%n", redCount);
  45. System.out.printf("Orange eggs: %d%n", orangeCount);
  46. System.out.printf("Blue eggs: %d%n", blueCount);
  47. System.out.printf("Green eggs: %d%n", greenCount);
  48. System.out.printf("Max eggs: %d -> %s",max,maxEggs);
  49. }
  50.  
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement