Avatar of ang3lus
ang3lus
 asked on

equalsIgnoreCase("") problem !!!!

Hi
i have problem to use this method
even i type correct or wrong string is still loop

         do {
                  menu();
                  empName = input.next();
            } while (!(empName.trim().equalsIgnoreCase("E2001"))
                        || !(empName.trim().equalsIgnoreCase("E277"))));

any suggestion to use not with comparing two string

thanks in advanced
Programming Languages-OtherJava

Avatar of undefined
Last Comment
ang3lus

8/22/2022 - Mon
Mick Barry

should be && not ||


            } while (!(empName.trim().equalsIgnoreCase("E2001"))
                        && !(empName.trim().equalsIgnoreCase("E277"))));
Mick Barry

or


            } while (!(empName.trim().equalsIgnoreCase("E2001")
                        || empName.trim().equalsIgnoreCase("E277")));
ang3lus

ASKER
there problem is not with loop
even if use !equalingnorecase with if ==> if statement always not true
if(!(empName.trim().equalsIgnoreCase("E2001"))
syso("print something");

is there any alternative way to use ! with string

i use trim to omit any space in string,  i used next() and nextLine()
same problem without any luck
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Mick Barry

no thats fine. what you are doing is the correct way to do the comparison
If it is false then the two strings must be the same
print them out to check

System.out.println(empName);
ang3lus

ASKER
iam still confuse with that
can you see what problem in this code

i create simple program to test  ! with equalIgnoreCase

if the user enter wrong course code the program should ask user to enter correct code
correct code is CS100 and CS200

even i enter CS100 and CS200 and other value , the loop is still continue
what's problem!!!

thanks


do
{
 crsCode = input.nextLine();
 System.out.println("wrong course code");
} while (!(crsCode.trim().equalsIgnoreCase("CS100")) !(crsCode.trim().equalsIgnoreCase("CS200"))

Open in new window

ASKER CERTIFIED SOLUTION
Mick Barry

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ang3lus

ASKER
thanks
i got it
thankd again
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.