java if(true)_Java中的if(布尔条件)

可以,然后呢..

// As you already stated, you know that a boolean defaults to false.

boolean turnedOn;

if(turnedOn) // Here, you are saying "if turnedOn (is true, that's implicit)

{

//then do this

}

else // if it is NOT true (it is false)

{

//do this

}

现在更有意义吗?

if语句将评估您放入其中的任何返回布尔值的代码,如果评估返回true,则输入第一个块.否则(如果值不为真,它将为false,因为布尔值可以为true或false)它将进入 – 是的,你猜对了 – else {}块.

一个更冗长的例子.

如果我被问到“你饿了吗?”,简单的回答是肯定的(真实的).或者不(假).

boolean isHungry = true; // I am always hungry dammit.

if(isHungry) { // Yes, I am hungry.

// Well, you should go grab a bite to eat then!

} else { // No, not really.

// Ah, good for you. More food for me!

// As if this would ever happen - bad example, sorry. ;)

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值