Integral of $f(x)$ converges but of $f(x)^2$ diverges? Does anybody know a function  $f$ that is continuous on $[0, \infty)$, so that $\int_{0}^{\infty} f(x)dx$ converges but $\int_{0}^{\infty} f(x)^2dx$ diverges? Thanks

EDIT: Sorry! I meant that $f$ is also continuous there.
A simple function with this property is $f(x)=\sin(x)/\sqrt{x}$, whose graph looks like so:



A simple appeal to the alternating series test shows that the integral converges, as
$$\int_0^{\infty} f(x) dx = \sum_{k=0}^{\infty}\int_{k\pi}^{(k+1)\pi} f(x) dx.$$

To see that the integral of $f(x)^2$ diverges, let's take a look at a graph of $f(x)^2$:



Each dashed rectangle that you see lives over an interval of the form
$[k\,\pi+\pi/6,k\,\pi+5\pi/6]$, which has length $4\pi/6$ or $2\pi/3$. The height of each rectangle is 
$$\frac{\sin^2(k\,\pi+5\pi/6)}{k\,\pi+5\pi/6} = \frac{1/4}{k\,\pi+5\pi/6}.$$

Thus, the sum total of the areas of those rectangles is
$$\sum_{k=0}^{\infty} \frac{\pi/6}{k\,\pi+5\pi/6} = \infty.$$

As those rectangles lie wholly under the graph of the squared function, the improper integral must diverge as well.
Can someone tell me what's wrong with the following? From @MarkMcClure's comment, there must be something wrong. It could must be a subtle point of improper Riemann integrals.

If $f$ is continuous on $[0,\infty)$ and $\int_0^\infty f &lt; \infty$, then $f(x) \to 0$ as $x \to \infty$, so there's some sufficiently large $R$ such that $f(x) \leq 1$ for $x &gt; R$. Then $\int_R^\infty f^2 \leq \int_R^\infty f$; in particular, $\int_R^\infty f^2 &lt; \infty$ (it exists). Since $f^2$ is the composition of continuous functions and $[0,R]$ is compact, $\int_0^R f^2$ also exists. Hence $\int_0^\infty f^2$ doesn't diverge.