Skip to content
Snippets Groups Projects
Commit ffa6f280 authored by lbr's avatar lbr
Browse files

switch statements

parent e72b02a9
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,9 @@ ...@@ -10,6 +10,9 @@
<component name="Git.Settings"> <component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/../.." /> <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/../.." />
</component> </component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProjectId" id="2KEUPgEewuByw0TGrg7D4kfckCr" /> <component name="ProjectId" id="2KEUPgEewuByw0TGrg7D4kfckCr" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" /> <component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState"> <component name="ProjectViewState">
...@@ -20,9 +23,24 @@ ...@@ -20,9 +23,24 @@
"keyToString": { "keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true", "RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true", "RunOnceActivity.ShowReadmeOnStart": "true",
"WebServerToolWindowFactoryState": "false" "WebServerToolWindowFactoryState": "false",
"settings.editor.selected.configurable": "preferences.lookFeel"
} }
}]]></component> }]]></component>
<component name="RunManager">
<configuration name="Main" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="Main" />
<module name="switch" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<recent_temporary>
<list>
<item itemvalue="Application.Main" />
</list>
</recent_temporary>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" /> <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager"> <component name="TaskManager">
<task active="true" id="Default" summary="Default task"> <task active="true" id="Default" summary="Default task">
...@@ -31,9 +49,13 @@ ...@@ -31,9 +49,13 @@
<option name="number" value="Default" /> <option name="number" value="Default" />
<option name="presentableId" value="Default" /> <option name="presentableId" value="Default" />
<updated>1673539215413</updated> <updated>1673539215413</updated>
<workItem from="1673539218018" duration="5385000" />
</task> </task>
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="Vcs.Log.Tabs.Properties"> <component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES"> <option name="TAB_STATES">
<map> <map>
......
File added
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
System.out.println("Hello world!"); int value = 4;
switch (value) {
case 1 -> System.out.println("Value was 1");
case 2 -> System.out.println("Value was 2");
case 3, 4, 5 -> {
System.out.println("Was a 3, a 4 or a 5");
System.out.println("Actually it was a " + value);
}
default -> System.out.println("Value was not 1 or 2");
}
String month = "aprilr";
System.out.println(month + " is in the " + getQuarter(month) + " quarter");
}
public static String getQuarter(String month) {
return switch (month) {
case "january", "february", "march" -> "1st";
case "april", "may", "june" -> "2nd";
case "july", "august", "september" -> "3rd";
case "october", "november", "december" -> "4th";
default -> {
String badResponse = month + " is bad ";
// The word yield is a new keyword, introduced for the switch expression,
// to return a value back.
yield badResponse;
}
};
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment