/*运算符之二:赋值运算符 = += -= *= /= %= */ class fu_zhi_yunsuanfu { public static void main(String[] args) { //赋值符号:= int i1 = 10; int j1 = 10; int i2,j2; //连续赋值 i2 = j2 = 10; System.out.println("--------------------------------"); //********************************* int num1 = 10; num1 += 2; //num = num1 + 2; System.out.println(num1); //12 int num2 = 12; num2 %= 5; //num2 = num2 % 5; System.out.println(num2); short s1 = 10; //s1 = s1 + 2; //编译不通过 s1 += 2; //不会改变变量本身的数据类型 System.out.println(s1); System.out.println("================================"); //练习1 int i = 1; i *=0.1; System.out.println(i); //0 i++; System.out.println(i); //1 //练习2 int m = 2; int n = 3; n *= m++; //n = n * m++; System.out.println("m=" + m); //3 System.out.println("n=" + n); //6 //练习3 int n1 = 10; n1 += (n1++) + (++n1); //n1 = n1 + (n1++) + (++n1); System.out.println(n1); //32 } }
运算符之二:赋值运算符
于 2022-07-02 17:48:51 首次发布