Java if 和 if else 问题

来源:互联网 发布:ug数控编程软件下载 编辑:程序博客网 时间:2024/06/01 10:44

当前面跟后面的else if 都满足条件时,按顺序只执行前面的代码块。

package com.test;public class TestIf {    public static void main(String[] args) {        int x = 2;        int y = 4;        if(x == 2) {            System.out.println("11");        } else if (y == 4) {            System.out.println("222");        } else {            System.out.println("no");        }    }}

输出结果为:11

0 0
原创粉丝点击