运算符的整理

运算符分为

算术运算符 + - *   /  %(取余,Java里面也叫模运算)

赋值运算符  += -= == != 

关系运算符 > < = 

逻辑运算符&&(与) ||(或)  !(非)

三元运算符? :

位运算符 >> <<  & | ^ ~

public static void main(String[] args){
    //ctrl + D:复制当前行到下一行
    long a = 1231351L;//long类型的后面都要加L
    int b = 120;
    short c = 30;
    byte b = 40;
    
   System.out.println(a+b+c+d);//long
   System.out.println(b+c+d);//int
   System.out.println(c+d);//int
    



}
public class demo2 {
    public static void main(String[] args) {
       //关系运算符返回的结果: 正确,错误
        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 Demo03 {
    public static void main(String[] args) {
        //++ -- 自增, 自减
        int a = 10;
        int b = 20;
        int c = 30;
        b = a++;  //先把a的值赋给b 然后a在自身自增
        c = ++a;  //a自身先增,然后把a的值赋给c
        System.out.println(b);
        System.out.println(c);

        double pow = Math.pow(3, 2);
        System.out.println(pow);

        //---------------------------------------------
        //逻辑运算符
        // 与(and) 或(or) 非(取反)
        boolean e = true;
        boolean f = false;

        System.out.println("a %% b:"+(e&&f));//逻辑 与 运算:两个都为真,结果才为真
        System.out.println("a || b:"+(e||f));//逻辑 或 运算:两个只要其中一个为真,结果就是真
        System.out.println("!(a && b):"+!(e&&f));//逻辑 非 运算:结果为真就为假,结果为假就为真

        //短路运算
        int o = 5;
        boolean p = (o<4)&&(pow++<4);
        System.out.println(p);
        System.out.println(o);
    }
public class Demo04 {
    public static void main(String[] args) {
        /*
        A = 0011 1100
        B = 0000 1101

        A&B = 0000 1100  //上下两个都为 1,才为 1
        A|B = 0011 1101  //上下只要有一个为 1,才为 1
        A^B = 0011 0001  //上下位置只要相同就等于它相同的那个数字
        ~B  = 1111 0010  //跟所属的数相反

        2 * 8 = 16 2*2*2*2
        效率极高!
        << *2
        >> /2
         */

    }
public class Demo05 {
    public static void main(String[] args) {
        int a = 10;
        int b = 20;

        a+=b;//a=a+b
        a-=b;//a=a-b

        System.out.println(a);

        //字符串连接符 + , String
        System.out.println(""+a+b);

        System.out.println(a+b+"");
    }
public class Demo06 {
    public static void main(String[] args) {
        //x ? y : z
        //如果x==true,则结果为y,否则结果为z
        int score = 80;
        String  type  = score < 60?"及格":"不及格";
        System.out.println(type);
    }
import com.yuan.base.*;//导入这个包中所有的数据
public class Demo07 {
    public static void main(String[] args) {
        //包的本质为文件夹
        //一般公司要用域名倒置写
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值