Skip to content

Instantly share code, notes, and snippets.

@nremond
Created March 31, 2017 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nremond/9844d349fb7a4903f2fbb05f01c4056b to your computer and use it in GitHub Desktop.
Save nremond/9844d349fb7a4903f2fbb05f01c4056b to your computer and use it in GitHub Desktop.
Switch statement with strings
class TestSwitch {
String day;
public TestSwitch(String day) {
this.day = day;
}
public void tellItLikeItIs() {
switch (day) {
case "MONDAY":
System.out.println("Mondays are bad.");
break;
case "FRIDAY":
System.out.println("Fridays are better.");
break;
case "SATURDAY": case "SUNDAY":
System.out.println("Weekends are best.");
break;
default:
System.out.println("Midweek days are so-so.");
break;
}
}
public static void main(String[] args) {
TestSwitch firstDay = new TestSwitch("MONDAY");
firstDay.tellItLikeItIs();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment