+ 1
name="john"; name2="carlos"; if(name <> name2 ) System.out.println("different"); //why eror?
eror
4 Respuestas
+ 2
error is actually in your syntax:
it's because "<>" doesn't just work, rather use "!=" (for not equal to).
it should and will work
+ 1
for strings you should use .equals()
if(name.equals(name2)){
System.out.println("same");
}
//use this, not an operator. plz.
+ 1
of course mine has no output. the names are different. mine will output if they are THE SAME.
you either need an else statement or a negation to see it.
if(! name.equals (name2)){
diff.}
if (name.equals (name2)){
same
} else {
diff
}
thats how it works. it returns a boolean.
my way works just fine. you should Not be using operators at all when comparing string values in java. its a Terrible idea.
and I've only ever seen <> as a negation in sql.
0
Michael I'm afraid your method doesn't just work. produces no output