双路选择: if-else 语句
来源:互联网 发布:php面试题大全 编辑:程序博客网 时间:2024/06/13 12:37
说明:
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.
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;
}
//通常情况下,如果语句块中仅包含一个语句,则相应花括号可以省略
对应流程图:
代码片段举例:
// ① 判别数字的奇偶性
// 方案:能为2整除的是偶数,反之则为奇数
if (number % 2 == 0)
System.out.println(number + " is even.");
else
System.out.println(number + " is odd.");
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.
0 0
- 双路选择: if-else 语句
- if else 、switch选择语句
- 条件选择语句if else switch
- if-else双选择结构
- IF-ELSE IF-ELSE语句
- C语言之选择流程语句:if--else
- 选择语句switch和if else的区别以及代码
- C语言(11)------选择结构if-else语句
- if-else选择结构
- Delphi if else 语句
- if~else 语句再认识
- if else 语句
- JavaScript If...Else 语句
- PHP If...Else 语句
- PHP If...Else 语句
- if-else语句
- JavaScript If...Else 语句
- JavaScript If...Else 语句
- [Ruby] split 的使用方法
- RX8025AC INTA周期电平输出的疑问
- java 读取图片转成
- 哈希表+双向链表的组合使用
- 使用SQLCipher对数据库加密
- 双路选择: if-else 语句
- Mac上的抓包工具Charles
- 稳压
- java Map定时过期类
- H3C的路由器配置命令详解
- 如何发外链才能让百度收录和提高排名?
- Manifest.xml-<supports-screens
- Oracle删除用户及表空间
- error while loading shared libraries问题解决