Formula for the $\mathbb{E}[X] = \sum_{n\geq1}P(X\geq n)$ with density function Let $X>0$ be non-negative random variable:


*

*Show that, if $X$ is an integer random variable, then $\mathbb{E}[X] = \sum_{n\geq1}P(X\geq n)$

*Find and prove the corresponding formula for the case, when $X$ has a density function.


For the first one, I have already found a solution: Find the Mean for Non-Negative Integer-Valued Random Variable
However, for the second one, I have tried by myself but I am not sure, whether my answer is correct. My answer is the following:
\begin{eqnarray*}
 \sum_{n=0}^{\infty}P(X>n)&\overset{\small P(X>n)=(1-P(X \leq n))}{=} \: &\sum_{n=0}^{\infty} (1-F_X(n))\\
 &=& \sum_{n=0}^{\infty} \left(1- \int_{-\infty}^{\infty}f(x)\ dx\right)\\
&= &\sum_{n=0}^{\infty} \left(\int_{-\infty}^{\infty}f(x)\ dx - \int_{-\infty}^{n}f(x)\ dx\right) \\
& =& \sum_{n=0}^{\infty} \left(\int_{-\infty}^{n}f(x)\ dx + \int_{n}^{\infty}f(x)\ dx - \int_{-\infty}^{n}f(x)\ dx\right) \\
& = &\sum_{n=0}^{\infty} \left(\int_{n}^{\infty}f(x)\ dx\right).
\end{eqnarray*}
I am not sure if $$ \int_{-\infty}^{\infty} f(x)\ dx=1 $$ hold in this case? I would appreciate any kind of remarks or help in this case.
 A: I think that the way your question is phrased is a bit misleading. If a random variable $X$ has a density $f(x)$ (that is absolutely continuous with respect to Lebesgue measure), then $X$ cannot be integer valued. So we should not expect to find a formula in terms of a sum $\sum_{n=0}^\infty P(X>n)$, but rather something like $\int_{0}^{\infty}P(X>x)\,\mathrm dx$. If we formally turn the discrete result you got for integer-valued random variables into a "continuous" result, then we may try to prove that
$$
\color{blue}{E[X] = \int_0^\infty P(X>x)\,\mathrm dx}
$$
since this is what we get by formally changing the discrete result
$$
E[X] = \sum_{n=0}^{\infty}P(X>n)
$$
into a continuous one. To prove the continuous result, try to mimic the proof in the discrete case, and note that you may find yourself changing the order of integration, which you can justify by invoking the Fubini-Tonelli theorem.
To your question about the density, it is true that when $X$ has a density $f(x)$, then $\int_{-\infty}^\infty f(t)\,\mathrm dt = 1$, since
\begin{align*}
\int_{-\infty}^\infty f(t)\,\mathrm dt = \lim_{x\to\infty}\int_{-\infty}^xf(t)\,\mathrm dt = \lim_{x\to\infty}F(x) = 1,
\end{align*}
because all cdfs have this property that $\lim_{x\to\infty}F(x) = 1$.
