0

I have the following code:

boolean[] myArray = new boolean[10];
int a, b;
       :
myArray[a * b] = myArray[a * b] ? false: true;
a++;

I am trying to simplify the following to one line:

myArray[a * b] = myArray[a * b] ? false: true;
a++;

Should it be:

myArray[a * b] = myArray[a++ * b] ? false: true;

or

myArray[a++ * b] = myArray[a * b] ? false: true;

I understand a++ means apply a then do the increment. However, my question here is should a++ be at the left side or right side of the assignment operator "=" ? Thanks!

Edamame
  • 23,718
  • 73
  • 186
  • 320
  • 3
    Neither. The one-liner versions are much harder to read and debug, even if you get them to do what you want. – elixenide Jun 04 '16 at 15:57
  • 3
    And `b = b ? false : true;` is more concisely written as `b = !b`. – Tunaki Jun 04 '16 at 16:00
  • @Tunaki, I modified the question, this is not really a duplicate. My question is actually should a++ be at right or left of the assignment. Thanks! – Edamame Jun 04 '16 at 16:46
  • @Edamame Then it is answered here: http://stackoverflow.com/questions/20339242/is-the-array-index-or-the-assigned-value-evaluated-first – Tunaki Jun 04 '16 at 16:57

0 Answers0