import javax.swing.*; public class SwitCase { public static void main (String[] args){ String hello=""; hello=JOptionPane.showInputDialog("Input a letter: "); char hi=hello; switch(hi){ case 'a': System.out.println("a"); } } }
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"); } } }
翻译自:https://stackoverflow.com/questions/6906001/how-do-i-used-a-char-as-the-case-in-a-switch-case