Created
July 29, 2011 07:58
-
-
Save prisoner/1113411 to your computer and use it in GitHub Desktop.
Strings in switch Statements
This file contains hidden or 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
public String getTypeOfDayWithSwitchStatement(String dayOfWeekArg) { | |
String typeOfDay; | |
switch (dayOfWeekArg) { | |
case "Monday": | |
typeOfDay = "Start of work week"; | |
break; | |
case "Tuesday": | |
case "Wednesday": | |
case "Thursday": | |
typeOfDay = "Midweek"; | |
break; | |
case "Friday": | |
typeOfDay = "End of work week"; | |
break; | |
case "Saturday": | |
case "Sunday": | |
typeOfDay = "Weekend"; | |
break; | |
default: | |
throw new IllegalArgumentException("Invalid day of the week: " + dayOfWeekArg); | |
} | |
return typeOfDay; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment