You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Switch1.java 398B

12345678910111213141516171819202122
  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 -> 1;
  12. case B -> 2;
  13. default -> 3;
  14. };
  15. return result;
  16. }
  17. }
  18. enum Color {
  19. R, G, B, Y;
  20. }