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

为什么赋值时,three前不加int

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);

提问者:慕姐2131086 2018-04-04 22:47

个回答

  • qq_篠弥_03901321
    2018-05-18 11:10:49

     因为第一次是int three=0 是初始化three为0,后面每次在这个int初始化基础上再次对three进行赋值,所以后面不用在加int了,如果加了int,后面再次赋值是在后面你再int基础上进行赋值的

  • qq_时光交错_0
    2018-05-17 19:31:16

    这道题的代码:

    int one = 10 ;
        int two = 20;
       int three = 0 ;
       int as=one+two;
       int sw=two+two;
       int dw=two+two-one;
       int ad=(one+two)*one;
       int asd=(ad/30)+two;
       int sc=(one+two)%(one+two);
      
      
       System.out.println("three=one+two==>"+as);
       System.out.println("three+=one==>"+sw);
       System.out.println("three-=one==>"+dw);
       System.out.println("three*=one==>"+ad);
        System.out.println("three/=one==>"+asd);
       System.out.println("three%=one==>"+sc);

  • 慕姐9519336
    2018-04-04 23:09:56

    three只是个变量名,使用前已经用int定义了,所以再使用的时候不需要再定义了