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

对否?为什么输出不对提交可以通过?

public class HelloWorld{

    public static void main(String[] args) {

   int one = 10 ;

        int two = 20 ;

        int three = 0 ;

        three = one + two ==>30;

        three += one ==> 40;

        three -= one ==> 30;

        three *= one ==> 300;

        three /= one ==> 30;

        three %= one ==> 0;

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

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

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

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

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

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

        为什么输出不对呢
       error: illegal start of expression
three = one + two ==>30;
^
error: illegal start of expression
three += one ==> 40;
^
error: illegal start of expression
three -= one ==> 30;
^
error: illegal start of expression
three *= one ==> 300;
^
error: illegal start of expression
three /= one ==> 30;
^
error: illegal start of expression
three %= one ==> 0;
^
6 errors


提问者:阿斯arth 2015-06-14 19:36

个回答

  • chavin
    2015-06-14 21:01:17
    已采纳

            three = one + two ==>30;

            three += one ==> 40;

            three -= one ==> 30;

            three *= one ==> 300;

            three /= one ==> 30;

            three %= one ==> 0;


    这些代码不对,语法不正确, 举个例子说明一下: three = one + two ==>30;   这一个是输出结果,是自己拼接出来的,你只要通过计算得到正确结果就可以了。

    three = one + two;

    System.out.println("three = one + two ==>" + three);  //three = one + two是自定义输出的