Zebra0.com

java switchJava

Java

Learn Java in step-by-step lessons.

switch: looking at one variable

The switch construct offers an alternative to nested if statements. Switch can be used when the test invloves a single variable with a small number of possible values.

The syntax is:

switch(variable) {
  case value: statement; statement; statement; break;
  case value: statement; statement; break;
  case value: statement; break;
  default: statement;
}

When a match is found, every statement is executed until there is a break.

Please study the material at each of the links below.

  1. Calulate tip based on service:Y or N

  2. Print season from month

GlossaryGlossary for switch lesson
Full Glossary