I have to check the convergence of the improper integral $$ \int_{0}^{\infty} \cos^2x\,dx .$$
I have tried to solve it in the following manner: $$\begin{align}\int_{0}^{\infty}\cos^2x\,dx &= \lim_{B \to \infty} \int_{0}^{B}\cos^2x\,dx \\&= \lim_{B \to \infty} \int_{0}^{B}(1-\sin^2(x))\,dx \\ &= \lim_{B \to \infty}[x]_{0}^{B} -\lim_{B \to \infty} \int_{0}^{B}\sin^2(x)\,dx .\end{align}$$
Now the first term tends to infinity as $B \to \infty,$ so the integral is not convergent.
But unfortunately the answer is given to be convergent. I don't understand how ?
Also I have proven in the same way that $$ \int_{0}^{\infty} (\sin x^2)^2\,dx $$ is divergent. So basically I think that if my process is wrong then I am wrong in both cases.
Am I wrong ? If so, looking for guidance then. Thank you.