How do I used a char as the case in a switch-case?
问题 How do I use a character in a switch-case? I will be getting the first letter of whatever the user inputs. 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"); } } } 回答1: public class SwitCase { public static void main (String[] args){ String hello = JOptionPane.showInputDialog("Input a letter: "); char hi = hello.charAt(0); /