1. Group Problem

Prove that if $(ab)^{2}=a^{2}b^{2}$ in a group G, then $ab=ba$.

My proof so far:

Now (ab)^{2}=a^{2}b^{2} for each a,b \in G,

so $a^{2}b^{2}=a^{2}b^{2}$

implies $a^{2}b^{2}=b^{2}a^{2}$

then, there exist a^{-1},b^{-1} in G

(a^-1)(a^2b^2)(b^-1) = (a^-1)(b^2a^2)(b^-1)

ab=ba.

Am I allow to switch the a and b like that?

Prove that if $ab^{2}=a^{2}b^{2}$ in a group G, then $ab=ba$.
Have you written the problem correctly?
Or should it be $(ab)^{2}=a^{2}b^{2}$???

If you do mean that then:
$\left( {ab} \right)^2 = a^2 b^2$
$\left( {ab} \right)^2 = \left( {ab} \right)\left( {ab} \right) = a^2 b^2$
$a^{ - 1} \left( {ab} \right)\left( {ab} \right)b^{ - 1} = a^{ - 1} \left( {a^2 b^2 } \right)b^{ - 1}$
$ba = ab$

3. Oops, yeah, that is right.

$
(ab)^{2}=a^{2}b^{2}
$