I have the following problem:
Let G be a group of order $p^2$ and assume that G is not abelian. I have just shown that $Z(G)$ is cyclic and has order p. Now I want to show that for each element $g\in G\setminus Z(G)$ we have $\operatorname{ord}(g)=p$.
Proof
Let $g\in G\setminus Z(G)$. We remark that $$card(G\setminus Z(G))=card(G)-card(Z(G))=p^2-p=p(p-1)$$Since we know that $\operatorname{ord}(g)\mid card(G)=p(p-1)$ we get that $\operatorname{ord}(g)=\{p,p-1,1\}$. Now let us assume that $\operatorname{ord}(g)=p-1$. Then $g^{p-1}=e$. But this means that $$g^p=g^{p-1}g=eg=g \Rightarrow p=1$$ Which is a contradiction to the assumption that p is prime. Now let us assume that $\operatorname{ord}(g)=1$. Then for all $g\in G\setminus Z(G)$ we have $g^1=g=e$. This means that $G\setminus Z(G)={e}$ which is also a contradiction. Therefore $\operatorname{ord}(g)=p$.
Does this works like this?