问答详情
源自:3-3 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);
        }
}
       

提问者:薄荷波 2016-03-17 19:05

个回答

  • 话世
    2016-03-17 19:09:11

    因为之前three已经被申明了是int类型的变量(同一个变量不能重复申明)。再给他赋值就会直接覆盖它原来的值。