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

一个赋值问题

three = one+ two; //为啥前面加上int数据类型就运行不了了呢?

提问者:森森0515 2019-09-04 21:40

个回答

  • 慕尼黑9030500
    2019-09-04 22:16:53
    已采纳

    public class HelloWorld{

        public static void main(String[] args) {

        int one = 10 ;

            int two = 20 ;

            int three = 0 ;这个地方已经有定义了three变量

            three=one+two;所以在这里加int会出现报错

    //

    error: variable three is already defined in method main(String[])
            int three=one+two;

    //

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

            three=three+one;

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

            three=three-one;

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

            three=three*one;

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

            three=three/one;

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

            three=three%one;

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

    }

    }