Advertisement
psi_mmobile

Untitled

May 11th, 2022
908
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1. public class MyClass {
  2.     public static void main(String args[]) {
  3.         java.util.Scanner scanner = new java.util.Scanner(System.in);
  4.         int numberOfBalls = scanner.nextInt();
  5.         String color = null;
  6.         double sum = 0.0;
  7.         for (int i = 0; i < numberOfBalls; i++) {
  8.             color = scanner.next();
  9.             switch(color) {
  10.                 case "red" : sum = sum + 5; break;
  11.                 case "orange" : sum += 10; break;
  12.                 case "yellow" : sum += 15; break;
  13.                 case "white" : sum += 20; break;
  14.                 case "black" : sum = Math.floor(sum/2.0);
  15.                 default : sum = sum;
  16.             }
  17.         }
  18.         System.out.printf("Sum : %.0f", sum);
  19.     }
  20. }
  21.  
  22.  
  23. /*
  24. 22
  25. black
  26. red
  27. yellow
  28. red
  29. white
  30. black
  31. blue
  32. red
  33. orange
  34. orange
  35. black
  36. green
  37. red
  38. purple
  39. white
  40. white
  41. orange
  42. orange
  43. red
  44. blue
  45. black
  46. white
  47. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement