go to previous page   go to home page   go to next page

Answer:

No


Example

We will get to those other rules shortly. Here is the previous example, with more explanation:

double discount;

char   code = 'B' ;   // Usually the value for code would come from data

switch ( code )
{
  case 'A':
    discount = 0.0;
    break;

  case 'B':
    discount = 0.1;
    break;

  case 'C':
    discount = 0.2;
    break;

  default:
    discount = 0.3;
}

System.out.println( "discount is: " + discount );
  1. The expression is evaluated.
    • In this example, the expression is the variable, code, which evaluates to the character 'B'.
  2. The case labels are inspected starting with the first.
  3. The first one that matches is case 'B'
  4. The statementList after case 'B' starts executing.
    • In this example, there is just one statement.
    • The statement assigns 0.1 to discount.
  5. The break statement is encountered which ends the statementList.
  6. The statement after the entire switch statement is executed.
    • In this example, that is the println() statement

QUESTION 7:

If code is 'W' what is discount?