Printing single java array element
I have several variations of the same program, each slightly different from the one before. Can someone give me an explanation why these produce the particular output for each individual implementation. 1) public class Main { public static void main(String[] args) { int x = 0; int[] arr = {2, 3, 5}; x = arr[x]; System.out.println(arr[x]); } } Output: 5 2) public class Main { public static void main(String[] args) { int x = 0; int[] arr = {2, 3, 5}; arr[x] = x; System.out.println(arr[x]); } } Output: 0 3) public class Main { public static void main(String[] args) { int x = 0; int[] arr = {2, 3, 5}; arr[x] = x++; System.out.println(arr[x]); } } Output: 3 4) public class Main { public static void main(String[] args) { int x = 0; int[] arr = {2, 3, 5}; arr[x] = ++x; System.out.println(arr[x]); } } Output: 3 I am especially confused about the last two implementations, with the use of "++x" vs "x++", and why they both produce the same result.