Let G be a nonabelian group of order $p^3$, where $p$ is a prime number. Prove that the center of $G$ is of order $p$.
Proof
Since $G$ is not abelian, the order of its center cannot be $p^3$. Since it is a $p$-group, the center cannot be trivial. So the order of $Z(G)$ is either $p^2$ or $p$.
Suppose, for contradiction, that $Z(G) = p^2$. Since $p$ is prime, we can assume that a subgroup $H= \langle p \rangle$ of order $p$ exists in $G$. We can also assume that $H$ and $Z(G)$ are disjoint. Otherwise, if there didn't exist a disjoint subgroup of order $p$, then the order of $G$ would be $p^2$. Since $Z(G)$ is the center, they commute with p. Since they commute with $p$, they must also commute with all powers of $p$. So $G = Z(G) \times H \implies$ G is abelian since $H$ and $Z(G)$ are abelian. So $|Z(G)|=p$.
Do you think my answer is correct?
Thanks in advance