desislava_topuzakova

Untitled

May 10th, 2021
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Balls {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int countBalls = Integer.parseInt(scanner.nextLine());
  8.  
  9. int totalPoints = 0;
  10.  
  11. int red = 0;
  12. int orange = 0;
  13. int yellow = 0;
  14. int white = 0;
  15. int picked = 0;
  16. int black = 0;
  17. for (int i = 1; i <= countBalls; i++) {
  18. String color = scanner.nextLine();
  19.  
  20. switch (color){
  21. case "red":
  22. red++;
  23. totalPoints = totalPoints + 5;
  24. break;
  25. case "orange":
  26. orange++;
  27. totalPoints = totalPoints + 10;
  28. break;
  29. case "yellow":
  30. yellow++;
  31. totalPoints = totalPoints + 15;
  32. break;
  33. case "white":
  34. white++;
  35. totalPoints = totalPoints + 20;
  36. break;
  37. case "black":
  38. black++;
  39. totalPoints = totalPoints / 2;
  40. break;
  41. default:
  42. picked++;
  43. break;
  44. }
  45. }
  46.  
  47. System.out.printf("Total points: %d%n", totalPoints);
  48. System.out.printf("Points from red balls: %d%n", red);
  49. System.out.printf("Points from orange balls: %d%n", orange);
  50. System.out.printf("Points from yellow balls: %d%n", yellow);
  51. System.out.printf("Points from white balls: %d%n", white);
  52. System.out.printf("Other colors picked: %d%n", picked);
  53. System.out.printf("Divides from black balls: %d%n", black);
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment