小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

11

 印度阿三17 2021-02-13

11

運算符

算術運算符: ,-,*,/,%, ,--

賦值運算符:=

關系運算符:>,<,==,<=,>=,!=instanceof

邏輯運算符:&&,||,!

位運算符:&,|,^,~,>>,<<,>>>(了解?。?

條件運算符:?:

拓展賦值運算符: =,-=,*=,/=

算術運算符

public class Demo01 {
    public static void main(String[] args) {
        //二元運算符    小技巧:Ctrl D 復制當前行到下一行
        int a = 10;
        int b = 20;
        int c = 30;
        int d = 35;
        System.out.println(a b);
        System.out.println(a%b);//取余  這里相除余數是10,故輸出10
        System.out.println(a-b);
        System.out.println(a*b);
        System.out.println(a/(double)b);//注意這里有小數,記得轉換


    }
}

不同類型相加,有l(wèi)ong類型就輸出long類型,沒有則輸出int類型

總之比int高的類型存在就輸出高的類型,沒有就輸出int

public class Demo02 {
    public static void main(String[] args) {
        int a = 123;
        long b = 11233333333L;
        byte c = 11;
        short d =222;
        System.out.println(a b c d);//long
        System.out.println(a c d);//int
        System.out.println( c d);//int
    }

}

,--

public class Demo04 {
    public static void main(String[] args) {
        //自增 ,自減    ,--
        //一元運算符
        int a = 10;
        int b = a  ;
        // 先給b賦值,再讓a 1
        int c =   a;
        //先給a 1,再讓c賦值
        System.out.println(a);
        System.out.println(b);
        System.out.println(c);
        //很多數學運算都使用Math工具
        double d =Math.pow(2,3);//冪運算
        System.out.println(d);
    }
}

關系運算符

public class Demo03 {
    public static void main(String[] args) {
        //關系運算符返回的結果:正確 or 錯誤,   布爾值
        //if
        int a = 10;
        int b = 20;
        System.out.println(a>b);
        System.out.println(a<b);
        System.out.println(a==b);
        System.out.println(a!=b);
    }
}

邏輯運算符

public class Demo05 {
    public static void main(String[] args) {
        boolean a = true;
        boolean b = false;
        System.out.println(a&&b);//&&  與,都是真則為真
        System.out.println(a||b);//||  或,有真則為真
        System.out.println(!b);//!    取反,真變假,假變真

        //短路運算:與運算中,監(jiān)測到假就停止運算
        int c = 5;
        boolean d = (c  <4)&&(c<4);
        System.out.println(c);
        System.out.println(d);//此時c已經自增,結果輸出6
        //調換順序
        int e = 5;
        boolean f = (e<4)&&(e  <4);
        System.out.println(e);
        System.out.println(f);
        //此時輸出5,說明短路了

    }
}

位運算符

public class Demo06 {
    public static void main(String[] args) {
        /*
        位運算,底層代碼,二進制
        A = 1000 0111
        B = 1100 0010
        ---------------------
        A&B=1000 0010
        A|B=1100 0111
        A^B=0100 0101
        !B=0011 1101

        2*8 怎么樣運算快 =2*2*2*2
        二進制數字
        1左移一位代表*2
        1右移一位代表/2
        這樣算效率極高
        <<   >>  左移    右移
         */
        System.out.println(2<<3);//輸出16
    }
}

拓展賦值運算符

偷懶用的

public class Demo07 {
    public static void main(String[] args) {
        int a = 10;
        int b = 20;
        a =b;//a=a b
        System.out.println(a);
        a-=b;//a=a-b
        System.out.println(a);
        //字符串連接符       String
        System.out.println(a b "");//輸出30,意為ab相加
        System.out.println("" a b);//輸出1020,意為字符串連接


    }
}

三元運算符

public class Demo08 {
    public static void main(String[] args) {
        //三元運算符  x ? y:z
        //x=true,輸出y,否則,輸出z
        int score = 80;
        String ef =score>60?"及格":"不及格";
        System.out.println(ef);
    }
}

學習自狂神說Java

來源:https://www./content-4-855901.html

    本站是提供個人知識管理的網絡存儲空間,所有內容均由用戶發(fā)布,不代表本站觀點。請注意甄別內容中的聯系方式、誘導購買等信息,謹防詐騙。如發(fā)現有害或侵權內容,請點擊一鍵舉報。
    轉藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多