Java如何使用if-then语句?
该if-then是最基本的控制流语句。仅当评估的测试表达式等于时,才会执行语句块true。让我们看下面的例子:
package org.nhooo.example.lang;
public class IfThenDemo {
public static void main(String[] args) {
int a = 10;
int b = 5;
// If the evaluation of a > b is true than the if block is
//被执行。在下面的块中,我们只打印该值
//的a大于b。
if (a > b) {
System.out.println("A(" + a + ") is bigger than B(" + b + ")");
}
//当我们在一个块中只有一个命令时,我们可以
//卸下块的打开和闭合支撑({..})。
//但是,最好始终用
//大括号。
if (b < a)
System.out.println("B(" + b + ") is smaller that A(" + a + ")");
}
}上面程序的结果是:
A(10) is bigger than B(5) B(5) is smaller that A(10)
热门推荐
10 香港老妈结婚祝福语简短
11 毕业立体贺卡祝福语简短
12 简短新年年会祝福语
13 评论小品祝福语大全简短
14 恭喜师兄结婚祝福语简短
15 员工集体辞职祝福语简短
16 高中新生祝福语 简短
17 装修祝福语男生搞笑简短
18 生日开业蛋糕祝福语简短