Find a L-sentence which is true in a structure $M$ iff the universe $A$ of $M$ consists of exactly two elements

Solution 1:

Yes, that works, although I found it a bit confusing. You could also say $$ \exists x\,\exists y\,(x \ne y) \wedge \neg \exists x\,\exists y\,\exists z\,(x \ne y \wedge x \ne z \wedge y \ne z),$$ which says "there are two distinct elements and it is not the case that there are three distinct elements," or

$$ \exists x\,\exists y\,(x \ne y \wedge \forall z\,(z = x \vee z = y)),$$ which says "there are two distinct elements such that every element is equal to one of the two."