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 婆婆高寿祝福语大全简短