<s>[INST] Most elegant method to calculate $\int^\pi_0 (x\sin x)^2 dx$ $\displaystyle \int^\pi_0 (x\sin x)^2 dx$. 
I can easily use integration by parts to solve this integral; however, it is quite messy and I'm just wondering if there exists another alternative method that is more elementary and elegant.
I have tried the substitutions $u = \pi -x$ and $u = \pi / 2 -x$ but they do not seem to help very much.
 [/INST] Using the identity $\sin^2(x)=\frac{1}{2}(1-\cos(2x))$, we have:
\begin{align*}
\int^\pi_0 x^2\sin^2 x\; dx &= \frac{1}{2}\int^\pi_0 x^2(1-\cos(2x)) dx \\
&= \frac{1}{2} \int^\pi_0x^2\;dx - \frac{1}{2}\int^\pi_0x^2\cos(2x)\;dx \\
&= \frac{\pi^3}{6} -\frac{1}{2} \left[\frac{1}{2}x^2\sin(2x)\right]_0^\pi + \frac{1}{2}\int_0^\pi x\sin(2x)\;dx \\
&= \frac{\pi^3}{6} + \frac{1}{2}\left[-\frac{1}{2}x\cos(2x)\right]_0^\pi + \frac{1}{2}\int_0^\pi\sin(2x)\;dx \\
&= \frac{\pi^3}{6} - \frac{\pi}{4}.
\end{align*}
</s>