1. 程式人生 > >java 運算符++的練習

java 運算符++的練習

報錯 一個 [] int bsp col div -a style

第一個練習:

public class Demo1{
    public static void main (String []args ){
    int a = 10;
    int b = 10;
    int c = 10;
    a = b++;   //a = 10,b = 11
    c = --a;   //a = 9 ,c = 9
    b = ++a;   //a = 10,b = 10
    a = c--;   //a = 9 ,c = 8
    System.out.println("a="+a+",b="+b+",c="+c);
    
    
    
    }
}

第二個練習:

public class Demo1{
    public static void main (String []args ){
    int x = 4;
          // 4     6     10
    int y =(x++)+(++x)+(x*10);
    System.out.println("x="+x+",y="+y);    //輸出x = 6    y = 60 
    
    
    
    }
}

第三個練習:

public class Demo1{
    public static void main (String []args ){
    
byte b = 10; b++; //b = (byte)(b+1) b = b + 1; //會報錯 //當byte與int進行混合運算的時候, 會提升int類型, 兩個int相加的結果還是int, 賦值給byte會損失精度 } }

java 運算符++的練習