Volume of a solid $y=\cos(x)$ and $y=0$ for the interval $0\le x \le \frac{\pi}2$.
I used method of shells to get:
$$2\pi\int_{0}^{\pi/2}x\cos(x)\,dx.$$
And I got: \begin{align} 2\pi\int_{0}^{\pi/2}x\cos(x)\,dx &= 2\pi[x\sin (x)+\cos(x)]\large|_0^{\pi/2} \\ &= 2\pi\left[\frac{\pi}{2}\,\sin\left(\frac{\pi}{2}\right)-\cos(0)\right]\\ &= 2\pi\left(\frac{\pi}{2}-1\right) \\ 2\pi\int_{0}^{\pi/2}x\cos(x)\,dx &= \pi^2-2\pi. \end{align}
Then I am doing it by method of slicing and got this as an answer:
I got the same answer: is it right?
You are correct. Using the distribute law $(\star)$, we have $$ 2 \pi \left( \frac{\pi}{2} - 1\right) \overset{(\star)}{=} (2 \pi) \left( \frac{\pi}{2} \right) - (2 \pi)(1) = \pi^2 - 2 \pi. $$