慕课网-安卓工程师初养成-4-1 Java条件语句之 if

来源:http://www.imooc.com/code/1353

生活中,我们经常需要先做判断,然后才决定是否要做某件事情。例如,如果考试成绩大于 90 分,则奖励一个 IPHONE 5S 。对于这种“需要先判断条件,条件满足后才执行的情况”,就可以使用 if 条件语句实现。

语法: 

执行过程: 

如:

注意哦:如果 if 条件成立时的执行语句只有一条,是可以省略大括号滴!但如果执行语句有多条,那么大括号就是不可或缺的喽~~

任务

验货时间到啦

请在编辑器空白处补全代码,实现功能“判断变量 one 的值是否是偶数”

运行结果:

1 public class HelloWorld {
2     public static void main(String[] args) {
3         int one = 20 ;
4         if (one % 2 == 0) {         
5             System.out.println("one 是偶数");
6         }
7     }
8 }
原文地址:https://www.cnblogs.com/chenliting/p/3960674.html