Daniel
Posts: 3
Nickname: jmmaverick
Registered: Jan, 2003
|
|
Re: How to "parse" characters
|
Posted: Jan 18, 2003 5:25 PM
|
|
Say, I am having a multiple choice quiz program, answer choices being A, B, C, and D. Switch statements I know only use characters and integers. When someone types in their answer choice, how do I convert it a character so that the switch statement will determine if it is right or not. Thnx (i.e
char answer = __________________(JOptionPane.showInputDialog("Question goes here, with answer choices listed"));
/*what goes above the line to make the input string a character, like Integer.parse int makes it an integer*/
switch (answer) { case A: System.out.println("You are correct."); break; case B: System.out.println("You are incorrect."); break; //and so on with cases }
|
|