2021-09-18

第二天补充

package operator;

public class operator {
    //运算符
    /*
     * 算术运算符:
     * 赋值运算符:
     * 关系运算符:
     * 逻辑运算符:
     * 位运算符:
     * 条件运算符:
     * 拓展赋值运算符
     */
    public static void main(String[] args) {
        // a++ ++a
        int a = 1;
        int b = a++;
        int c = ++a;
        System.out.println(b);
        System.out.println(c);
        System.out.println("-------------------------------------------");


        //Math数学类 3^2的次方
        double d = Math.pow(3,2);
        System.out.println(d);
        System.out.println("-------------------------------------------");


        //逻辑运算符 //与(and) 或(or) 非(取反)
        boolean a1 = true;
        boolean b1 = false;
        System.out.println("a1&&b1:"+(a1&&b1));//逻辑与运算:两个变量都为真,结果为true
        System.out.println("a1||b1:"+(a1||b1));//逻辑或运算:两个变量一个为真,结果为true
        System.out.println("!(a1&&b1):"+!(a1&&b1));//如果是真则为假,如果是假则为真


        //短路运算
        int c1 = 5;
        boolean b2 = c1<4&&c1++<4;
        System.out.println(c1);
        System.out.println(b2);
        System.out.println("-------------------------------------------");


        //位运算
        /*
        * << 左移 *2 >> 右移 /2
        * */
        System.out.println(2<<3);//本身就有一个2 本身2 *2这才是第一个*2*2 得出 2*2*2*2=16
        System.out.println("-------------------------------------------");

        //条件运算符
        int i = 10;
        int n = 20;
        i+=n;      // i = i + n;
        i-=n;      // i = i - n;
        System.out.println(i);
        System.out.println("-------------------------------------------");

        //输出为1020字符串在前面会把里面的变成字符串类型使用(i+n)里面的数据正常运算不会被当做字符串加在一起
        System.out.println(""+i+n);
        //输出为30字符串在后面前面的int类型正常运算
        System.out.println(i+n+"");
        System.out.println("-------------------------------------------");

        
        // x ? y : z 会返回一个结果
        //如果x为true,则结果为y,否则为z;
        int score = 80;
        String str = score>60 ? "及格" : "不及格";
        System.out.println(str);//结果为及格
    }
}

```java


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值