双路选择: if-else 语句
2016-03-24 13:47
661 查看
说明:
An if-else statement decides the execution path based on whether the condition istrue 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.");
A WORD :Death or Alive,is not a must,but a choice.
相关文章推荐
- 常用工具收集
- 使用SQLCipher对数据库加密
- Shuffle'm Up(模拟)
- RX8025AC INTA周期电平输出的疑问
- iOS申请证书,Certificates, Identifiers &Profiles 简介
- spring自定义标签
- OJ链接(持续更新)
- 哈希表+双向链表的组合使用
- [Ruby] split 的使用方法
- 未来不迎,当下不杂,过往不恋
- 操作系统之实验一 命令解释程序的编写
- 操作系统 实验一
- org.apache.commons.lang.StringUtils(StringUtils工具类的常用方法)
- 关于ScrollView嵌套Listview遇到的问题
- Sqlite数据库加密方法总结
- Spring hibernate 声明式事务配置
- oracle 相关
- SQL SERVER 高级编程 - 自定义函数 拾忆
- Android 如何使用使用数据库
- 让Hibernate输出SQL语句参数配置