Java中的赋值运算符

赋值运算符是指为变量或常量指定数值的符号。如可以使用 “=” 将右边的表达式结果赋给左边的操作数。

Java 支持的常用赋值运算符,如下表所示:


代码:

public class HelloWorld{
    public static void main(String[] args) {
     int one = 10 ;
        int two = 20 ;
        int three = 0 ;
       
        three = one+two;
        System.out.println("three= one+two ==>" + three);
        three += one;
        System.out.println("three +=one ==>" + three);
        three -=one;
        System.out.println("three -=one ==>" + three);
        three *=one;
        System.out.println("three *= one ==>" + three);
        three /=one;
        System.out.println("three /=one ==>" + three);
        three %=one;
        System.out.println("three %=one ==>" + three);


运行结果:

three= one+two ==>30
three +=one ==>40
three -=one ==>30
three *= one ==>300
three /=one ==>30
three %=one ==>0