+ 1
What is the ! symbol used for?
10 Respostas
+ 1
In most languages it negates a boolean expression, e.g.
if( a==b) then a and b have to be equal.
if (!(a==B)) then it's true if a and b are not equal.
many languages offer aswell the negated equal sign: if(a!=b)
0
In addition to the person who replied, it's essentially the word "not"
if (A != B){
System.out.print ("B is bigger");
}
else {
System.out.print ("A is bigger");
}
Here we say that if A is not bigger than B, then we print B. Otherwise A is bigger. Hope this comment and the one posted by another user helped out.
0
@ares The comparison operator in your example is wrong. You just know A and B are equal or not or you have to fit the println()'s
0
@Andreas, I believe you are mistaken. The syntax is correct and works.
0
not
0
@Ares The syntax is correct but the semantic is not.
If you compare A and B by using '!=' you are not able to tell us whether A is bigger than B or B bigger than A. You just can say they are unequal. That's what I wanted to say.
0
That was the point of my syntax.
0
Please watch you code again. Your 'else' case should be A equals B not 'A is bigger'.
Otherwise I did misunderstand something, then I am sorry
0
I wrote down whatever I remembered from basic courses.
0
I already said that's a good example but it may confuses due to the non fitting print content