1. 程式人生 > 其它 >jpa+springboot,資料查詢異常check the manual that corresponds to your MySQL server version for the right ..

jpa+springboot,資料查詢異常check the manual that corresponds to your MySQL server version for the right ..

Java語言支援如下運算子

  1. *算術運算子:+, -, , /, %, ++, --
  2. 賦值運算子:=
  3. 關係運算符:> , < , >= , <=, ==, !=, instanceof
  4. 邏輯運算子:&&,||,!與或非
  5. 位運算子:&, |, ^, ~, >>, <<, >>>(瞭解!!!)
  6. 條件運算子:?,:
  7. *擴充套件賦值運算子:+=, -=, =, /=

算術運算子和關係運算符

public class Demo01 {
    public static void main(String[] args) {
        //二元運算子
        //Ctrl+D :複製當前行到下一行
        int a = 10;
        int b = 20;
        int c = 30;
        int d = 40;
        System.out.println(a+b);
        System.out.println(a-b);
        System.out.println(a*b);
        System.out.println(a/b);//輸出結果為0,因為a和b都是int型別,運算值取整數
        System.out.println(a/(double)b);//強制轉換資料型別,輸出結果為0.5
    }
}


public class Demo02 {
    public static void main(String[] args) {
        byte  a = 8;
        short b = 10;
        int   c = 123;
        long  d = 253654663L;
        System.out.println(a+b+c+d);//long型別
        System.out.println(a+b+c);//int型別
        System.out.println(a+b);//int型別
        //如果多個型別中有long型別,結果也為long型別,沒有long型別都是int型別,如果有個是double型別,結果一定也是double型別
    }
}

public class Demo03 {
    public static void main(String[] args) {
        //關係運算符返回的結果:正確,錯誤  布林值
        int  a = 10;
        int  b = 20;
        int  c = 21;
        System.out.println(a>b);//返回結果false
        System.out.println(a<b);//返回結果true
        System.out.println(a==b);//返回結果false
        System.out.println(a!=b);//返回結果true
        //%  取餘模運算,
        System.out.println(c%a);//取餘數
    }
}

自增自減運算子、初識Math類

public class Demo04 {
    public static void main(String[] args) {
        //++  --  自增,自減 一元運算子
        int  a = 3;
        int  b = a++; //執行完這行程式碼後,先給b賦值,再自增
        // a++   a=a+1
        System.out.println(a);
        int  c = ++a; //執行完這行程式碼前,再自增,再給c賦值
        int  d = ++b;
        System.out.println(a);
        System.out.println(b);
        System.out.println(c);
        System.out.println(d);
        //a++先用後加,++a先加後用;a就是c運算後賦的值,b++的值為4,但是先賦的值是3(輸出就是3),然後自增1,變成了4,到c的時候先自增後再加1,最後的結果就是5,最後又賦值給了a,所有a的值也是5;
        // 冪運算  2^3  2*2*2=8  很多運算我們會採用工具進行運算
        double pow=Math.pow(3,2); //Math類提供了很多科學工程計算需要的一些方法和常數,很多特殊的運算都需要藉助於它!
        System.out.println(pow);
    }
}

邏輯運算子、位運算子、條件運算子

//邏輯運算子  與(and)或(or)非(取反)
public class Demo05 {
    public static void main(String[] args) {
        boolean  a = true;
        boolean  b =false;
        System.out.println("a && b:"+(a&&b));      //邏輯與運算:兩個變數都為真,結果才為true
        System.out.println("a || b:"+(a||b));     //邏輯或運算:兩個變數有一個為真,則結果才為true
        System.out.println("!(a && b):"+!(a&&b));//邏輯與運算:如果是真則變為假;如果是假則變為真
        //短路運算   如果第一個數值為假,後面的就不會計算。
        int c = 5;
        boolean d = (c<4)&&(c++<4);
        System.out.println(d);
        System.out.println(c); //返回結果為5,沒有執行後面的c++引數
    }
}


//位運算
public class Demo06 {
    public static void main(String[] args) {
        /*
        A = 0011 1100
        B = 0000 1101
        A&B =  與  0000 1100  如果對應位都是1,則為1,否則為0
        A|B =  或  0011 1101  如果對應位都是0,則為0,否則為1
        A^B =  異或 0011 0001 如果對應位相同,則為0,否則為1
        ~B    取反  1111 0010  和B的值相反
        << 左移 >>右移
                 */
        System.out.println(2<<3);//相當於2*2*2*2的值
        System.out.println(3<<3);//返回結果為24
        //   << 相當於*2  >> 相當於/2
    }
}

public class Demo07 {
    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);
        //字串連線符  +
        System.out.println(a+b);//返回結果是30
        System.out.println(""+a+b);//返回結果1020   在+號連線符兩側,如果出現了string型別,都會把後面的操作都轉換成string型別,再進行連線。
        System.out.println(a+b+"");//返回結果30,   string型別前面會先進行運算。
    }
}

三元運算子

//三元運算子
public class Demo08 {
    public static void main(String[] args) {
        // x ? y : z
        // 如果x==true,則結果為y,否則結果為z
        int  sorce = 80;
       String type = sorce < 60 ? "不及格":"及格";//如果成績小於60分,返回不及格,否則返回及格
        System.out.println(type);  //返回結果及格
    }
}