Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Switch1.java 455B

12345678910111213141516171819202122232425
  1. public class Switch1 {
  2. public static void main(String[] argv) {
  3. System.out.println(one(Color.R));
  4. System.out.println(one(Color.G));
  5. System.out.println(one(Color.B));
  6. System.out.println(one(Color.Y));
  7. }
  8. public static int one(Color color) {
  9. int result = switch (color) {
  10. case R -> 0;
  11. case G -> {
  12. int number4 = 8 / 2;
  13. yield number4 /4;
  14. }
  15. case B -> 2;
  16. default -> 3;
  17. };
  18. return result;
  19. }
  20. }
  21. enum Color {
  22. R, G, B, Y;
  23. }