.equals question help please
Hi again all,
Is there anyway you can compare two things in a .equals statement.
For example.
If(symptoms.equals("headache" ||"head hurts"))
{
System.out.println"BLah blah blah");
}
I tried that but it gives a weird error so i was wondering is there ANOTHER method i need to combine to make that to work?
MS
[490 byte] By [
Progr@mera] at [2007-11-26 12:20:59]

# 1
If I'm a little vague tell me so i can elaborate on this Please.
# 2
if(symptoms.equals("...") || symptoms.equals("...."))
# 3
> if(symptoms.equals("...") ||> symptoms.equals("...."))Nice let me try it.
# 4
> if(symptoms.equals("...") ||
> symptoms.equals("...."))
It works, but once again i'm having a trouble with the loop.
If you try this code it works fine but when it asks if you would like to try again and you hit "y" it just skips to the else statement.
Here it is:
import java.util.*;
import java.text.*;
public class Medicine
{
public static void main(String[]args)
{
String symptom, answer;
Scanner scan=new Scanner(System.in);
do{
System.out.println("Please enter the symptom(s) you are experiencing:");
symptom=scan.nextLine();
System.out.println();
System.out.println();
if(symptom.equalsIgnoreCase("I have a headache") ||(symptom.equalsIgnoreCase("My head hurts" )))
{
System.out.println("You need tylenol or asprin");
}
else
System.out.println("I'm sorry i did not find any medicine which will meed your symptom");
System.out.println("Would you like to try again?");
answer=scan.next();
}while(answer.equalsIgnoreCase("y"));
}
}
Any ideas of why it would do that?
Thanks MS
# 5
Set answer using "nextLine" instead of "next".
# 6
Try swapping out the last two lines in your do...while loop for this.answer=scan.nextLine();}while(answer.toLowerCase().charAt(0) == 'y');
# 7
> Set answer using "nextLine" instead of "next".
For some reason there is a bug with Jgrasp of when you put next line it doesn't execute it.
Captain Morgan found that out for me last time i posted somethign with a loop.
Try it for yourself, it skips the NextLine, but executes on NExt.
I asked my professor he said it might be a bug.
Ty, any other ideas?
# 8
> Try swapping out the last two lines in your
> do...while loop for this.
> answer=scan.nextLine();
> }while(answer.toLowerCase().charAt(0) == 'y');
It igves an error saying:
; expected after while statement. Heres the code i changed.
System.out.println("Would you like to try again?");
answer=scan.nextLine();
}while(answer.toLowerCase().charAt(0) == 'y'));
}
Message was edited by:
Progr@mer
# 9
> Captain Morgan found that out for > me last time i posted somethign > with a loop.That wasnt a bug. Try reading the end of that thread, an explanation was posted by flounder as to why it was doing that.
# 10
> > Set answer using "nextLine" instead of "next".> > For some reason there is a bug with Jgrasp of when you put next line it doesn't execute it.I don't use Jgrasp, so I have no idea.
# 11
> ; expected after while statement. > Heres the code i changed.You have too many ending parentheses in your while loop.
# 12
> Set answer using "nextLine" instead of "next".
Wow tried it with line and it actually worked this time.
Nice man, but wierd. here it is.
do{
System.out.println("Please enter the symptom(s) you are experiencing:");
symptom=scan.nextLine();
System.out.println();
System.out.println();
if(symptom.equalsIgnoreCase("I have a headache") ||(symptom.equalsIgnoreCase("My head hurts" )))
{
System.out.println("You need tylenol or asprin");
}
else
System.out.println("I'm sorry i did not find any medicine which will meed your symptom");
System.out.println("Would you like to try again?");
answer=scan.nextLine();
}while(answer.equalsIgnoreCase("y"));
}
Ty all I'm sure i'll be back with another question shortly.
# 13
> Wow tried it with line and it actually worked this
> time.
Like I said, read through your old thread to see the difference between next() and nextLine().
http://forum.java.sun.com/thread.jspa?threadID=792181&messageID=4502353#4502353
nextLine() reads the whole line while next() only reads the next token.
# 14
answer=scan.nextLine();
# 15
> answer=scan.nextLine();Youre a quick one arent you! ;-)
# 16
No, obviously not. I didn't read the second page. But when I wanted to delete my message, I got an icon "You are not allowed to edit theis message".Sorry. Many words where nothing should be read.