if(!checkSecondNum())
Where checkSecondNum is a method of boolean return type and why we used exclamatory sign in if statement please describe me in brief.
if(!checkSecondNum())
Where checkSecondNum is a method of boolean return type and why we used exclamatory sign in if statement please describe me in brief.
n1=!true // 返回 false
n2=!false // 返回 true
n3=!"Cat" // 返回 false
!
是逻辑非运算符。这意味着当checkSecondNum()
返回false
执行将进入 if 块。
!false = true
和
!true = false
您应该看一下Java运算符的摘要:
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/opsummary.html
在这种特定情况下,!
是一个合乎逻辑的NOT
.
我认为您的程序只是想做当checkSecondNum()
不正确的事情时,然后执行if{}
. 所以你应该使用!
.