运算符

运算符

public class Demo03 {
   public static void main(String[] args) {
       //++ -- 自增自减 一元运算符
       int a = 3;
       int b = a++;//执行完代码后,先给b赋值,再自增
       //a++ a=a+1
       int c = ++a;//执行完代码前,先自增,再给b赋值
       //++a a=a+1
       System.out.println(a);
       System.out.println(b);
       System.out.println(c);
       //幂运算 2*2
       double pow =Math.pow(2,3);
       System.out.println(pow);


       //逻辑运算符 与(and) 或(or) 非(取反)
       boolean e = true;
       boolean f = false;
       System.out.println(e && f);//两者为真才是true
       System.out.println(e || f);//两者有一个是真,就是true
       System.out.println(!(e&&f));//如果是真则为假。如果是假,则为真
  }
}

(>>或<<,<<右移,每右移一位,就扩大两倍,>>则相反)

0000 0000 0

0000 0001 1

0000 0010 2

0000 0100 4

0000 1000 8

 int a = 10;
       int b = 20;
       System.out.println(""+a+b);//ab拼在一起
       System.out.println(a+b+"");

       //三元运算符
       //x ? y : z,如果x==true,则结果为y,否则结果为z
       int score = 70;
       String type =score <60 ? "不及格":"及格";
       System.out.println(type);

 



posted @ 2022-08-02 13:40  小新新Blog  阅读(29)  评论(0)    收藏  举报