If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

How do i make it Not Equal to?

THANKX FOR the replies!!
BUt i need more favor to ask.
now, I want it to output "Wrong ID" If only the password matches "open" and output "Wrong Password" If only the user ID matches "admin."
How do i do it?

You can use the following character "!" which will reverse a value from true to false and vice versa. for example the following statement

if( !input1.equals( "admin" ) && !input2.equals( "open" )) {

}

This means if input1 not equal to admin and input2 not equal to open

Cheers,
Ess

I just wanted to quickly point out the difference between Kezzer's code and ess' code (or is it ess's?)

In Kezzer's code we saw the != used with Strings and while this works in occasion it can provide some unpredictable behavior.

Since Java is essentially a fully pointers language, the == != sometimes does things unexpected to the Java beginner. Let me give an example.

With Kezzer's code,

Code:

if(input1 != "admin")

It looks like input1 is checking if it's the same as the String "admin" but this is actually incorrect. What's really going on is it's checking to see if the Pointer input1 is pointing to the same location as the temporary pointer "admin".

Which sometimes is true, and sometimes is false, depending on where it is allocated in memory.

So for a much safer and always true method you want to check the actual String inside of the pointer, use ess' code. It calls upon a helper method (of equals to which you will learn more about in your continuation of Java) to check that the Strings are the same, not that the pointers correspond.