What will be printed on the screen if the program with the main function defined as follows is executed?

I have following Java code:

public static void main(String[] args) {
    int x = 1;
    x += 1 + x++ == 1 ? x++ : ++x;
    System.out.println("x = " + x);
}

I am asked what will be printed. I ran it and it has output

x = 4

Can you explain what is happening in this code?