switch case java character code example
Example 1: java switch case
switch(x){
case(0): //if x == 0
//do some stuff
break;
//add more cases
default: //when x does not match any case
//do some stuff
break;
}
Example 2: switch case java with char
public class SwitCase {
public static void main (String[] args){
String hello = JOptionPane.showInputDialog("Input a letter: ");
char hi = hello.charAt(0); //get the first char.
switch(hi)
{
case 'a': System.out.println("a");
}
}
}