Solution to Abstract Algebra by Dummit & Foote 3rd edition Chapter 5.1 Exercise 5.1.1
Show that the center of a direct product is the direct product of the centers: $$Z(G_1 \times \cdots \times G_k) = Z(G_1) \times \cdots Z(G_k).$$ Deduce that a direct product of groups is abelian if and only if each of the factors is abelian.
Solution: We proceed by induction on $k$.
For the base case $k=2$, let $G$ and $H$ be groups.
($\subseteq$) Let $(g,h) \in Z(G \times H)$. Then for all $(a,b) \in G \times H$, $$(ga, hb) = (g,h)(a,b) = (a,b)(g,h) = (ag,bh).$$ Thus $ag = ga$ and $bh = hb$ for all $a \in G$ and $b \in H$; hence $g \in Z(G)$ and $h \in Z(H)$. Thus $(g,h) \in Z(G) \times Z(H)$.
($\supseteq$) Let $(g,h) \in Z(G) \times Z(H)$. Now for all $a \in G$ and $h \in H$, $$(g,h)(a,b) = (ga,hb) = (ag,bh) = (a,b)(g,h).$$ Thus $(g,h) \in Z(G \times H)$. Thus $Z(G \times H) = Z(G) \times Z(H)$.
Now suppose the conclusion holds for any product of $k$ groups for some $k \geq 2$. Then $$Z(\times_{i=1}^{k+1} G_i) = Z(\times_{i=1}^k G_i \times G_{k+1}) = Z(\times_{i=1}^k G_i) \times Z(G_{k+1}) = \times_{i=1}^k Z(G_i) \times Z(G_{k+1}) = \times_{i=1}^{k+1} G_i.$$ By induction, the result holds for any finite direct product.
Now let $G = \times_{i=1}^k G_i$ be a finite direct product of groups.
If each factor $G_i$ is abelian, then $$Z(G) = Z(\times_{i=1}^k G_i) = \times_{i=1}^k Z(G_i) = \times_{i=1}^k G_i = G;$$ hence $G$ is abelian.
If $G$ is abelian, then $$\times_{i=1}^k Z(G_i) = Z(\times_{i=1}^k G_i) = Z(G) = G = \times_{i=1}^k G_i.$$ If we let $\pi_i$ denote the $i$th coordinate projection, we have $G_i = \pi_i[G] = Z(G_i)$. Hence $G_i$ is abelian for each $i$.