Problem evaluating $ \int_{0}^{\pi/2}\frac{x}{\tan x}dx $ I am trying to evaluate  $\int_0^{\pi/2}\frac{x}{\tan x} \, dx$. This is how I started:
$$  \int_0^{\pi/2} x\cot x \, dx$$
Integrating by parts we get:
$$x\ln\left|\sin x\right| - \int_0^{\pi/2}\ln\left|\sin x\right| \, dx $$
Since $x$ is between $0$ and $\pi/2$, we can drop the absolute value.
$$x\ln \sin x - \int_0^{\pi/2}\ln \sin x \, dx $$
Integrating the second integral again by parts we get:
$$x\ln \sin x - x\ln \sin x - \int_0^{\pi/2}\frac{x}{\tan x} \, dx$$
Now we take the last integral to the other side to get $$2\int_0^{\pi/2}\frac{x}{\tan x} \, dx = 0$$ and therefore $\int_0^{\pi/2} \frac{x}{\tan x} \, dx = 0$. However, when I checked the memo, it said the answer was $\frac{\pi}{2} \ln2$. What is wrong with my solution? Please help me find where I went wrong.

Let $\displaystyle{I = \int^{\frac{\pi}{2}}_0 x \cot x \, dx}$. Now
\begin{align*}I &= \int^{\frac{\pi}{4}}_0 x \cot x \, dx + \int^{\frac{\pi}{2}}_{\frac{\pi}{4}} x \cot x \, dx = \int^{\frac{\pi}{4}}_0 x \cot x \, dx  + I_1\end{align*}
For the integral $I_1$, set $x = \frac{\pi}{2} - u, dx = - du$ while for the limits of integration at $x = \frac{\pi}{4}, u = \frac{\pi}{4}$ while at $x = \frac{\pi}{2}, u = 0$. Thus
\begin{align*}I_1 &= - \int^0_{\frac{\pi}{4}} \left (\frac{\pi}{2} - u \right ) \cot \left (\frac{\pi}{2} - u \right ) \, du\\
&= \int^{\frac{\pi}{4}}_0 \left (\frac{\pi}{2} - u \right ) \tan u \, du\\
&= \frac{\pi}{2} \int^{\frac{\pi}{4}}_0 \tan u \, du - \int^{\frac{\pi}{4}}_0 u \tan u \, du\\
&= \frac{\pi}{2} \Big{[}-\ln |\cos u| \Big{]}^{\frac{\pi}{4}}_0 - \int^{\frac{\pi}{4}}_0 u \tan u \, du\\
&= \frac{\pi}{4} \ln 2 - \int^{\frac{\pi}{4}}_0 u \tan u \, du
\end{align*}
So for integral $I$ we have
\begin{align*}I &= \frac{\pi}{4} \ln 2 + \int^{\frac{\pi}{4}}_0 x \cot x \, dx - \int^{\frac{\pi}{4}}_0 x \tan x \, dx\\
&= \frac{\pi}{4} \ln 2 + \int^{\frac{\pi}{4}}_0 x \left (\cot x - \tan x \right ) \, dx\\
&= \frac{\pi}{4} \ln 2 + \int^{\frac{\pi}{4}}_0 x \left (\frac{\cos x}{\sin x} - \frac{\sin x}{\cos x} \right ) \, dx\\
&= \frac{\pi}{4} \ln 2 + \int^{\frac{\pi}{4}}_0 x \frac{\cos^2 x - \sin^2 x}{\sin x \cos x} \, dx\\
&= \frac{\pi}{4} \ln 2 + \int^{\frac{\pi}{4}}_0 2x \frac{\cos 2x}{\sin 2x} \, dx\\
&= \frac{\pi}{4} \ln 2 + \int^{\frac{\pi}{4}}_0 2x \cot 2x \, dx
\end{align*}
For the integral to the right, set $u = 2x, du = 2 dx$ while for the limits of integration, at $x = 0, u = 0$, while at $x = \frac{\pi}{4}, u = \frac{\pi}{2}$. Thus
\begin{align*}I &= \frac{\pi}{4} \ln 2 + \frac{1}{2} \int^{\frac{\pi}{2}}_0 u \cot u \, du\\
&= \frac{\pi}{4} \ln 2 + \frac{1}{2} I\\\Rightarrow \frac{1}{2} I 
&= \frac{\pi}{4} \ln 2\\\Rightarrow I 
&= \frac{\pi}{2} \ln 2.\end{align*}
Thus $\displaystyle{\int^{\frac{\pi}{2}}_0 x \cot x \, dx = \frac{\pi}{2} \ln 2}$ as indicated in one of the comments.
