赋值运算符练习
//赋值运算符练习
public class SetValueExercise {
public static void main(String[] argz) {
//练习1
short s=3;
//s = s+2;//编译失败
s += 2;
//区别:前者会改变变量类型,不符合规格,后者不改变变量类型。
//练习2
int i = 1;
i *= 0.1;//编译可以通过:i = i*0.1
System.out.println(i);//0
i++;
System.out.println(i+"\n");//1
//练习3
int m = 2;
int n = 3;
n *= m++;//n = n*m++
System.out.println("m="+m);//3
System.out.println("n="+n+"\n");//6
//练习4
int n1 = 10;
n1 += (n1++)+(++n1);//n = n//10 + (n++)//10 + (++n)//12
System.out.println("n1="+n1);//32
}
}
输出:
0
1
m=3
n=6
n1=32