Created
March 31, 2017 12:56
-
-
Save nremond/9844d349fb7a4903f2fbb05f01c4056b to your computer and use it in GitHub Desktop.
Switch statement with strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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