Switch case in Java at Hackveda

Dhiraj Singh
Sep 3, 2018 · 2 min read

Switch statement in Java is used to allow a variable for equality against a list of value.Variables used in Switch case is integer, convertible integer(short,char,byte) and String.

Syntax of Switch Case

Syntax of Switch Case

Let understand with help of an example.

We show output of a grade of student marks obtained

  1. If student have A grade then Show “Excellent
  2. If student have B grade then Show “Very good
  3. If student have C grade then Show “Good
  4. If student have B grade then Show “Average
  5. If user enter other than these character then show “Enter value between A-D”
Grade Example

Output

Output

Note

break — The break statement in Java is used to terminate loop immediately and move control on next statement.

default — It is used when no keyword match then default then default keyword executed.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade