传智播客java基础班冯佳老师整理,还会持续更新,请关注冯佳老师的微博fengjia_2553868@qq.com

1:位运算符

2:三元运算符

int x,y,z;
x = 5;
y = 10;
z = x > y ? x : y;

3:程序运行流程&顺序结构

4:if语句

5:if语句嵌套

    int x = 2, y = 1;
    if(x==1){
        if(y==1){
            System.out.println("a");
        }else{
            System.out.println("b");
        }
    }else{
        if(y==1){
            System.out.println("c");
        }else{
            System.out.println("d");
        }
    } 

6:switch

    例如:我们做一年有四季的例子:
    int month = 4;
    switch (month){
    case 3:
    case 4:
    case 5:
        System.out.println(month+"月是春季");
    break;
    case 6:
    case 7:
    case 8:
        System.out.println(month+"月是夏季");
    break;
    case 9:
    case 10:
    case 11:
        System.out.println(month+"月是秋季");
    break;
    case 12:
    case 1:
    case 2:
        System.out.println(month+"月是冬季");
    break;
    default:
        System.out.println(month+"月没有这样的月份")

    }//上述例子就是三个case里面的值输出都一样的,所以我们省略了break;这样会少写几行代码,提高效率

* 2,当我们把 default 不是写在最后,default 里面还没有写break的是时候,switch里的表达式与各个case里的值都不匹配的时候,上面两个条件同时满足的话,程序在default里执行完了还会再去执行case里的语句

    例如:
    int x = 3;
    switch (x){

    case 4:
        System.out.print("a");
    break;
    default:
        System.out.print("b");//当程序执行到了default但是他没有break,下面的case值不再判断,程序继续执行
    case 5:
        System.out.print("c");
    case 6:
        System.out.print("d");
    break;//遇到break,程序跳出
    case 7:
        System.out.print("e");
    }

7:while