双路选择: if-else 语句

说明:

   An if-else statement decides the execution path based on whether the condition is
true or false.
   A one-way if statement performs an action if the specified condition is true. If the condition
is false, nothing is done. But what if you want to take alternative actions when the condition
is false? You can use a two-way if-else statement. The actions that a two-way if-else
statement specifies differ based on whether the condition is true or false.

语法格式:

     if(boolean-expression) {
        statement(s)-for-the-true-case;
      }
     else{
        statement(s)-for-the-false-case;
      }

     //通常情况下,如果语句块中仅包含一个语句,则相应花括号可以省略

 

对应流程图:

flowchart of if-else statement

代码片段举例:

/ ① 判别数字的奇偶性
// 方案:能为2整除的是偶数,反之则为奇数
if (number % 2 == 0)
     System.out.println(number + " is even.");
else
     System.out.println(number + " is odd.");

A WORD :Death or Alive,is not a must,but a choice.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值