equalsIgnoreCase("") problem !!!!

ang3lus
ang3lus used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Mick BarryJava Developer
Top Expert 2010

Commented:
should be && not ||


            } while (!(empName.trim().equalsIgnoreCase("E2001"))
                        && !(empName.trim().equalsIgnoreCase("E277"))));
Mick BarryJava Developer
Top Expert 2010

Commented:
or


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

Author

Commented:
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
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

Mick BarryJava Developer
Top Expert 2010

Commented:
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);

Author

Commented:
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

Java Developer
Top Expert 2010
Commented:
you haven't changed the conditionas I suggested above
try this

import java.util.Scanner;

public class Input {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		String crsCode = null;
		do {
			if (crsCode != null) {
				System.out.println("wrong course code: " + crsCode);
			}
			crsCode = input.nextLine();
		} while (!(crsCode.trim().equalsIgnoreCase("CS100")
				|| crsCode.trim().equalsIgnoreCase("CS200")));
		System.out.println("Code entered: " + crsCode);
	}
}

Open in new window

Author

Commented:
thanks
i got it
thankd again

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial