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

public class HelloWorld{
    public static void main(String[] args) {
     int one = 10 ;
        int two = 20 ;
        int three = 0 ;
        three=one+two;   
        three+=one;    
        three-=one;     
        three*=one;     
        three/=one;  
        three%=one;

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



提问者:半成品LY 2015-08-16 14:04

个回答

  • Raine
    2015-08-16 14:54:39
    已采纳

    意义是不同的,计算机在编译的时候是按照顺序的,所以你看到第一组代码的输出three的值是不一样的,但是第二组代码的输出值都是同一个