Advertisement
Yee0418

Enum Q.1

Sep 4th, 2024 (edited)
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.47 KB | None | 0 0
  1. enum Mood {
  2.     HAPPY,
  3.     SAD,
  4.     ANGRY
  5. }
  6.  
  7. Mood myMood = Mood.Happy;
  8.  
  9. switch(myMood){
  10.     case HAPPY:
  11.         System.out.println("Happy!");
  12.     case SAD:
  13.         System.out.println("SAD :(");
  14.         break;
  15.     case ANGRY:
  16.         System.out.println("*F!@#");
  17.         break;
  18.     default:
  19.         System.out.println("AAAAAAA");
  20.         break;
  21. }
  22.  
  23.  
  24.  
  25. // Because there is no break statement in the HAPPY case, this program will print out "Happy!" and "SAD :("
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement