switch case for if in java code example
Example 1: switch statement in java
public class SwitchStatementExample
{
public static void main(String[] args)
{
char grade = 'A';
switch(grade) {
case 'A' :
System.out.println("Distinction.");
break;
case 'B' :
case 'C' :
System.out.println("First class.");
break;
case 'D' :
System.out.println("You have passed.");
case 'F' :
System.out.println("Fail. Try again.");
break;
default :
System.out.println("Invalid grade");
}
System.out.println("Grade is: " + grade);
}
}
Example 2: java switch case
switch(x){
case(0):
break;
default:
break;
}