= means assignment ... which you shouldn't be using here
== is the logical comparator for equality ... which you should.
x=0 actually sets x to 0
... so if (x=0) considers the value of x after this assignment. This is 0 and translates to boolean false. This if condition is not run.
x=1 sets x to 1.
... so if (x=1) considers the value of x after this assignment. This is 1 and non-zero values translate to boolean true. So it does what is in this if block.
Once it has done some if block ... it doesn't need to consider any furtherelseif block, so it won't even look at assigning x=2.
If you want it to print "x is 2" then change all the "=" into "=="