Flowchart of a break Statement

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.

Answer:

0.3

Flowchart of a break Statement

Here is the example program fragment (again) and a flowchart that shows how it works. The box in the flowchart "evaluate code" means to get the current value of code. In a larger program this would usually be different every time.

flowchart
double discount;
// Usually code would be read in
char   code = 'B' ;    

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 );


QUESTION 8:

(Trick Question:) What would be the discount if code were 'a' ?