Let $$f(x) = \left\{ \begin{array}{lr} x^2 \cos\left(\frac{1}{x}\right) &: x \ne 0 \\ 0 &: x = 0 \end{array}\right.$$ Prove that $f(x)$ is continuous for all $x \in \mathbb{R}$.
I can use a theorem which states: let $I, J \subseteq \mathbb{R}$ be intervals. Let $f:I \to \mathbb{R}$ and $g:J \to \mathbb{R}$ and suppose $f(I) \subseteq J$. Suppose $f$ is continuous at $y \in I$ and $g$ is continuous at $f(y)$. Then $g \circ f$ is continuous at $y$.