Let $X$ be a continuous non-negative random variable (i.e. $R_x$ has only non-negative values). Prove that $$E(X) = \int_{0}^{\infty} P(X>x)\,dx = \int_{0}^{\infty} (1-F_X(x))\,dx$$ where $F_X(x)$ is the CDF for $X$. Using this result, find $E(X)$ for an exponential ($\lambda$) random variable.
I know that by definition, $F_X(x) = P(X \leq x)$ and so $1 - F_X(x) = P(X>x)$
The solution is: $$\int_{0}^{\infty} \int_{x}^{\infty} f(y)\,dy dx = \int_{0}^{\infty} \int_{0}^{y} f(y)\,dy dx = \int_{0}^{\infty} yf(y) dy.$$
I'm really confused as to where the double integral came from. I'm also rusty on multivariate calc, so I'm confused about the swapping of $x$ and $\infty$ to $0$ and $y$.
Any help would be greatly appreciated!