课程: Java Essential Training: Syntax and Structure
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Switch expressions
- [Instructor] Switch expressions are similar to switch statements. However, they allow you to directly assign a value when a case is matched. In this example, we're using switch statements to assign a value to the variable message. Switch expressions provide a simpler way to do this. As opposed to declaring message on a standalone line, we could actually initialize it with the result from a switch expression. We can add an equal sign after message and move the switch structure to the right side of the equal sign. Also, we can simplify the cases by replacing :message= with just an arrow, which we type using dash and a greater than sign. This means the same thing, which is, if grade is A for example, a sign, excellent job to the message, variable. Let me do that for the rest of the cases as well. Another nice thing about switch expressions is that they do not need a break statement as there is no fall through like with…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。
内容
-
-
-
-
-
-
If statements4 分钟 44 秒
-
(已锁定)
If-else statements3 分钟 5 秒
-
(已锁定)
If-else-if statements4 分钟 22 秒
-
(已锁定)
Switch statements5 分钟 2 秒
-
(已锁定)
Switch expressions3 分钟 3 秒
-
(已锁定)
Relational operators2 分钟 17 秒
-
(已锁定)
Logical operators3 分钟 55 秒
-
(已锁定)
Short circuit logic2 分钟 37 秒
-
(已锁定)
Code Solution: Change for a dollar game1 分钟 4 秒
-
-
-
-
-
-
-