Results 1 to 9 of 9
Thread: Simple fix?
- 02-04-2011, 12:29 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 12
- Rep Power
- 0
Simple fix?
I'm obviously doing something wrong, seeing as I'm getting errors. But, what exactly am I doing wrong? Am I using the OR operator incorrectly?
This is for a conversational program I'm testing my skills in.
System.out.println("Hey! nice of you to join me! How are you?");
if (response.equals ("bad" || "Bad")){
System.out.println("I'm sorry to hear that. Why so?");}
That's the only place I'm getting an error. any idea why?
Help gladly appreciated. Sorry to bother.
- 02-04-2011, 12:32 AM #2
that is not correct syntax for Java. You need to write two separate conditions, one for each version of "bad".
- 02-04-2011, 12:33 AM #3
Or you can use the equalsIgnoreCase method.
-
You need to make all expressions valid boolean expressions.
Java Code:if (response.equals("foo") ||response.equals("bar")) { }
- 02-04-2011, 12:34 AM #5
Member
- Join Date
- Jan 2011
- Location
- Gainesville, FL
- Posts
- 45
- Rep Power
- 0
What kind of error are you getting? Off the bat, I see that you have nothing actually going into your "response" variable.
you can also do
That way the user can type "bad", "bAD", Bad", etc. and it will still return true.Java Code:response.equalsIgnoreCase("bad")
- 02-04-2011, 12:43 AM #6
Member
- Join Date
- Feb 2011
- Posts
- 12
- Rep Power
- 0
I was just about to post an error message, but all is now well. Thanks for the help, and once again, sorry to bug you guys.
- 02-04-2011, 01:11 AM #7
Member
- Join Date
- Feb 2011
- Posts
- 12
- Rep Power
- 0
Oh hey, is there anyway for me to make it so if the user inputs something like:
not tooo badd
the program just takes keywords, like not too bad, and goes based off of that? Everyone types different and I won't feel accomplished if I couldn't implement this for everyone.
- 02-04-2011, 01:23 AM #8
Member
- Join Date
- Jan 2011
- Location
- Gainesville, FL
- Posts
- 45
- Rep Power
- 0
Without manually correcting the strings based on what you think they meant, you cannot really do that. Everyone types different, but different is wrong.
- 02-04-2011, 01:26 AM #9
Member
- Join Date
- Feb 2011
- Posts
- 12
- Rep Power
- 0
Similar Threads
-
simple app-help please
By skuzzie in forum New To JavaReplies: 7Last Post: 11-08-2010, 12:07 AM -
New simple application using a simple database
By webbusiness23 in forum New To JavaReplies: 9Last Post: 08-03-2009, 02:55 AM -
Simple Help....
By jpnym15 in forum New To JavaReplies: 1Last Post: 11-11-2008, 02:33 PM -
Help with a very simple method for a very simple beginner.
By cakeman in forum New To JavaReplies: 2Last Post: 05-04-2008, 05:27 PM -
simple GUI
By dim_ath in forum New To JavaReplies: 3Last Post: 01-07-2008, 03:00 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks