9 Replies Latest reply: Jun 5, 2012 2:06 AM by TPD-Opitz RSS

    diffcult to understand expression computaion having operator such as i++

    941218
      HI, everyone,

      i write a short program to test expression computaion having operator such as i++ or ++i, but can't understand some results , especially for those including i++, could anyone can explain in details.


      public class Main {

      /**
      * @param args the command line arguments
      */
      public static void main(String[] args) {
      int j=0;
      j=++j + ++j;
      System.out.println("++j + ++j:"+j);

      int l=0;
      l=l++ + l++ ;
      System.out.println("l++ + l++:"+l);

      int k=0;
      k=k++ + ++k;
      System.out.println("k=k++ + ++k:"+k);

      int m=0;
      m=++m + m++ + m++;
      System.out.println(" m=++m + m++:"+m);

      int n=0;
      n=++n + n;
      System.out.println("n=++n + n:"+n);

      int p=0;
      p=p++ + p;
      System.out.println("p=p++ + p:"+p);

      int q=0;
      q=q + ++q;
      System.out.println("q=q + ++q:"+q);

      int r=0;
      r=r + r++;
      System.out.println("r=r + r++:"+r);


      }