Describe the Switch Statement.
By in on Sep 17 2019
• Dec, 2019 15

switch (variable/expression) {case value1: // statements break;case value2: // statements break; .. .. ... .. .. ...default: // statements}

Here the variable should be premitive datatype like byte,int short,char .floating point is not allowed .For more follow the link
https://www.programiz.com/java-programming/switch-statement

https://www.javatpoint.com/java-switch

• 0
• Sep, 2019 17

Syntax

Switch(variable){ case 0: . . .  case n-1: default:}

This is a type of control statement in which we are a single variable is checked for multiple values and if neither value matches the code corresponding to default is executed.

• Switch case does not allow variables to be taken as the case value.
• Only uniques case values are acceptable.
• Each case is suffixed by a break statement, to make sure that only the matched case code executes
import static java.lang.System.out; class Csharpcorner {  public static void main(String[] args)  {  int i=0;  switch(i)  {  case 0:  case 1:  case 2:  case 3:  case 4:  case 5:  case 6:out.print(i);  break;  default: out.print("No value");  }  } }

For a detailed tutorial on Java Control and Loop Statements please visit https://www.c-sharpcorner.com/article/java-loops-and-control-statements/

• 0