How to comprehend $E(X) = \int_0^\infty {P(X > x)dx} $ and $E(X) = \sum\limits_{n = 1}^\infty {P\{ X \ge n\} }$ for positive variable $X$?

Suppose $X$ is an integrable, positive random variable. Then,

if $X$ is arithmetic, we have $E(X) = \sum\limits_{n = 1}^\infty {P\{ X \ge n\} }$
and

if $X$ is continuous, we have $E(X) = \int_0^\infty {P(X > x)dx} $.

How to understand these two formulas intuitively?

Solutions Collecting From Web of "How to comprehend $E(X) = \int_0^\infty {P(X > x)dx} $ and $E(X) = \sum\limits_{n = 1}^\infty {P\{ X \ge n\} }$ for positive variable $X$?"

If you follow the proof in the discrete case, it goes a long way to understanding the idea in the continuous case.

Assume $X$ is discrete, taking values $0,1,2,\ldots$. Then for $n\geq 0$,
$$
P(X\geq n) = P(X=n) + P(X=n+1) + \cdots = P(n) + P(n+1) + \cdots
$$
where of course the sum converges since $X$ is a random variable.

Now if we consider the sum of all these probabilities, then
$$
\sum_{n=1}^\infty P(X \geq n) = \sum_{n=1}^\infty \sum_{k=n}^\infty P(k).
$$
Fix $N$. How many times does $P(N)$ appear in this double summation? Well, in the sum indexed by $k$, $P(N)$ only appears if $N \leq n$, so $P(N)$ appears exactly $N$ times. Therefore
$$
\sum_{n=1}^\infty \sum_{k=n}^\infty P(k) = \sum_{N=1}^\infty NP(N) = E(X).
$$
What we have done, of course, is to use the discrete version of Fubini’s theorem to interchange the order of summation. In the continuous case, the idea is similar, though the intuitive explanation is a bit less rigorous; here it’s easier to rely on Fubini’s theorem more directly.

@newguy has already written you the answer if $X$ is discrete and if $X$ is continuous and has density $f$ then
$$
\int_{0}^{\infty}P(X > x) dx = \int_{0}^{\infty} \left(\int_{x}^{\infty} f(t) dt \right)dx,
$$
we can change orders of the integrals (using Fubini’s theorem) so
$$
\int_{0}^{\infty} \int_{0}^{t} f(t) dx dt = \int_{0}^{\infty} f(t) \left(\int_{0}^{t} 1 dx\right) dt = \int_{0}^{\infty} f(t) t dt = E(X).
$$

Here is another approach:

Integration by parts works for the continuous case:
$$\int_0^\infty P(X>x)dx=\int_0^\infty (1-F(x)) dx.$$
Then use the substitutions: $u=1-F(x)$, $du=-f(x)dx$, $dv=dx$, $v=x$:
$$\int_0^\infty (1-F(x)) dx= x(1-F(x))\Big|_0^\infty+\int_0^\infty x f(x)dx=0+E(X).$$

I’ve assumed that
$$\displaystyle\lim_{x\rightarrow\infty}x(1-F(x))=0.$$
The above limit reduces to $x^2f(x)\rightarrow0$ as $x\rightarrow\infty$. This seems reasonable, since $xf(x)$ being integrable requires it to decay faster than $x^{-1}$, but maybe there is a counterexample where a random variable has finite mean, but $x^2f(x)$ does not converge to zero.