The Artima Developer Community
Sponsored Link

Java Answers Forum
How to "parse" characters

3 replies on 1 page. Most recent reply: Jan 18, 2003 7:32 PM by Ugo Posada

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Daniel

Posts: 3
Nickname: jmmaverick
Registered: Jan, 2003

How to "parse" characters Posted: Jan 13, 2003 9:31 PM
Reply to this message Reply
Advertisement
I am writing a program in which i want to have GUI prompts.
I know if you have a interger as an input for the prompt you use Interger.parseInt. Is there a way to do the same with characters? thanks


Antonas

Posts: 11
Nickname: tony
Registered: May, 2002

Re: How to "parse" characters Posted: Jan 14, 2003 8:53 AM
Reply to this message Reply
What Do you mean ? What do You want exactly to do with characters (provide an example) ?

When You do Integer.parse("123") You are parsing String represented integers.

Daniel

Posts: 3
Nickname: jmmaverick
Registered: Jan, 2003

Re: How to "parse" characters Posted: Jan 18, 2003 5:25 PM
Reply to this message Reply
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
}

Ugo Posada

Posts: 37
Nickname: binaryx
Registered: Dec, 2002

Re: How to "parse" characters Posted: Jan 18, 2003 7:32 PM
Reply to this message Reply
The switch statement is used to conditionally perform statements based on an integer expression, not on strings. So, basically you would have to use an if/else, if you only have 5 options tops your code won't be cluttered.

Flat View: This topic has 3 replies on 1 page
Topic: Extracting Classnames, attributes and showing relationship Previous Topic   Next Topic Topic: Urgent Help needed

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use