课程: Java Essential Training: Syntax and Structure

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Switch statements

Switch statements

- [Instructor] The switch statement is a decision structure that solves a problem in a similar way that the if-else-if decision structure does. It's ideal for cases when you have more than two paths. The difference between the if-else-if and the switch statement is that if-else-if checks if the condition is true, whereas the switch statement checks for equality. In this example, we'll have a user enter their grade, and then, using a switch statement, print a message based on the student's letter grade. In this new grade message class, we've already asked the user to enter their letter grade, and we've scanned that in, and stored it inside of this grade variable, and we've also declared a variable for message, but we don't know the value of this message just yet. To determine which message to print, we'll use the switch decision structure. In order to invoke this, we type switch, a set of parentheses, and a set of curly…

内容