新建AssignTest.java
public class AssignTest{
public static void main(String[] args){
int a = 10;
int b = 20;
int c = 0;
c = a + b;
System.out.println("c = a + b = " + c); // c= 30
c += a;
System.out.println("c += a = " + c); // c=40
c -= a;
System.out.println("c -= a = " + c); // c=30
c *= a;
System.out.println("c *= a = " + c); // c=300
a = 10;
c = 15;
c /= a;
System.out.println("c /= a = " + c); // c=1.5 = 1
a = 10;
c = 15;
c %= a;
System.out.println("c %= a = " + c); // 取差 c=5=15-10
c &= a;
System.out.println("c &= a = " + c);
c ^= a;
System.out.println("c ^= a = " + c); //
c |= a;
System.out.println("c |= a = " + c);
c <<= 2;
System.out.println("c |= a = " + c);
c >>= 2;
System.out.println("c <<= 2 = " + c);
c >>= 2;
System.out.println("c >>= 2 = " + c);
}
}
保存,打开cmd -> cd /文件目录下 -> javac AssignTest.java -> java AssignTest -> 输出 !