问答详情
源自:3-3 Java中的赋值运算符

请问我这样写代码哪里不对?

public class HelloWorld{

    public static void main(String[] args) {

   int one = 10 ;

        int two = 20 ;

        int three = 0 ;

        int num1=one+two;

        int num2=three+=one;

        int num3 =three-=one;

        int num4 =three*=one;

        int num5 =three/=one;

        int num6 =three%=one;

        System.out.println("three = one + two ==>"+num1);

        System.out.println("three = one += two ==>"+num2);

        System.out.println("three = one -= two ==>"+num3);

        System.out.println("three = one *= two ==>"+num4);

        System.out.println("three = one /= two ==>"+num5); 

        System.out.println("three = one %= two ==>"+num6);     

    }


提问者:yeezus_mac 2017-09-23 15:37

个回答

  • 层层嫩牛堡
    2017-09-23 15:44:22
    已采纳

    一条语句中不可有两个赋值符号

  • 马小跳666
    2017-09-23 15:48:14

    public class HelloWorld{

        public static void main(String[] args) {

       int one = 10 ;

            int two = 20 ;

            int three = 0 ;

            System.out.println(three = one + two );

            System.out.println(three = one += two );

            System.out.println(three = one -= two );

            System.out.println(three = one *= two);

            System.out.println(three = one /= two); 

            System.out.println(three = one %= two );     

        }