+ 1

What is the ! symbol used for?

5th Jan 2018, 6:28 PM
Dennis O
Dennis O - avatar
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)
5th Jan 2018, 6:31 PM
Andreas K
Andreas K - avatar
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.
5th Jan 2018, 6:36 PM
Ares Xena
Ares Xena - avatar
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
5th Jan 2018, 6:38 PM
Andreas K
Andreas K - avatar
0
@Andreas, I believe you are mistaken. The syntax is correct and works.
5th Jan 2018, 6:44 PM
Ares Xena
Ares Xena - avatar
0
not
5th Jan 2018, 7:01 PM
Readyer
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.
5th Jan 2018, 7:36 PM
Andreas K
Andreas K - avatar
0
That was the point of my syntax.
5th Jan 2018, 7:37 PM
Ares Xena
Ares Xena - avatar
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
5th Jan 2018, 7:56 PM
Andreas K
Andreas K - avatar
0
I wrote down whatever I remembered from basic courses.
5th Jan 2018, 7:59 PM
Ares Xena
Ares Xena - avatar
0
I already said that's a good example but it may confuses due to the non fitting print content
5th Jan 2018, 8:01 PM
Andreas K
Andreas K - avatar