|
|
Subject:
Testing a String Input in Java (very easy)
Category: Computers > Programming Asked by: tamkins-ga List Price: $5.00 |
Posted:
25 Feb 2004 16:34 PST
Expires: 25 Feb 2004 16:50 PST Question ID: 310827 |
Why doesn't this program work? Specifically, you can answer yes, the 'Debug' line confirms that answer is "yes", but you still get the third message. I tried using a StringTokenizer as well, and that didn't help. Here is the program: import java.io.*; public class AnswerTest { public static void main (String[] args) throws Exception { System.out.println("Please enter yes or no."); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String answer = br.readLine(); System.out.println("Debug: answer = \"" + answer + "\"."); if (answer == "yes" || answer == "Yes") System.out.println("You said yes."); else if (answer == "no" || answer == "No") System.out.println("You said no."); else System.out.println("You said something else."); } } |
|
There is no answer at this time. |
|
There are no comments at this time. |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |