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)
热门推荐
7 简短的二胎祝福语
10 简短霸气女儿生日 祝福语
11 祝福语高考小众诗句简短
12 元旦祝福语20秒简短
13 老师过年祝福语大全 简短
14 一生祝福语简短
15 产检祝福语简短霸气
16 朋友店开张祝福语简短
17 生日爱情祝福语大全简短
18 朋友女儿生日祝福语 简短