Last active
April 28, 2022 22:15
-
-
Save lekeCoder/eac22934513da63373ad62b21d6c2220 to your computer and use it in GitHub Desktop.
switch and when example 1
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
// print day of the week based on day number (1 - 7) | |
int day = 3; | |
switch(day){ | |
case 1: | |
System.out.println("Monday"); | |
break; | |
case 2: | |
System.out.println("Tuesday"); | |
break; | |
case 3: | |
System.out.println("Wednesday"); | |
break; | |
case 4: | |
System.out.println("Thursday"); | |
break; | |
case 5: | |
System.out.println("Friday"); | |
break; | |
case 6: | |
System.out.println("Saturday"); | |
break; | |
case 7: | |
System.out.println("Sunday"); | |
break; | |
} | |
// prints "Wednesday" |
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
// print day of the week based on day number (1 - 7) | |
val day = 3; | |
when(day){ | |
1 -> println("Monday") | |
2 -> println("Tuesday"); | |
3 -> println("Wednesday"); | |
4 -> println("Thursday"); | |
5 -> println("Friday"); | |
6 -> println("Saturday"); | |
7 -> println("Sunday"); | |
} | |
// prints "Wednesday" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment