Example 2 Let $a, b$ be positive integers, $n$ be a given positive odd number, and $a+b=n$. Find the maximum value of $a b$.

Analysis: Since under the given conditions it is impossible to achieve $a=$ $b$, the solution cannot be obtained using the arithmetic mean inequality.
Solution 1: Let $n=2k+1$, i.e., $a+b=2k+1$.
By symmetry, assume without loss of generality that $a \leqslant k, b \geqslant k+1$, then,
$$
\begin{array}{l}
(a-k)(b-k) \\
=ab-k(a+b)+k^{2} \leqslant 0 .
\end{array}
$$

Thus, $ab \leqslant k(a+b)-k^{2}$
$$
\begin{array}{l}
=kn-k^{2}=k(n-k)=k(k+1) \\
=\frac{n-1}{2} \cdot \frac{n+1}{2}=\frac{n^{2}-1}{4} .
\end{array}
$$

Therefore, $(ab)_{\max}=\frac{n^{2}-1}{4}$ (when $a=\frac{n-1}{2}, b=\frac{n+1}{2}$).

Solution 2: From the identity $ab=\frac{1}{4}\left[(a+b)^{2}-(a-b)^{2}\right]$, we get
$$
ab=\frac{1}{4}\left[n^{2}-(a-b)^{2}\right] .
$$

It is evident that when $a-b=1$, i.e., $a=\frac{n+1}{2}, b=\frac{n-1}{2}$, $ab$ reaches its maximum value $\frac{n^{2}-1}{4}$.