Finding a constant in a density function 
Suppose
  $$
f(x)= \begin{cases} 0, & \text{for }x<0, \\ \\ kx, & \text{for } 0\le x < 1, \\ \\0, & \text{for } x\ge1 \end{cases}
$$
  is the density of a random variable $X$. How do I find k?


The book says the solution is $2$.
I apologize if this is unsolvable, incoherent and/or missing information. This is from my maths schoolbook which is full of such mistakes. I copied the problem as it is.
 A: I'm assuming that the $f$ you have written is a probability density fuction of a random variable $X$. A defining property is that $\int f(x) \; dx =1$ for all pdf's. In our case,
$$
\int f(x) \; dx = \int_0^1 kx \; dx = \frac{k}{2}
$$
and so $k$ must be equal to two.
A: $f$ is the density of the continuous random variable $X$. Its distribution function is $F(x)=\int_{-\infty}^xf(x)dx$. You must have that the probability of the whole space $\Omega$ is 1 so
$$P(\Omega)=P(X\in\mathbb{R})=\lim_{t\to+\infty}F(t)=\int_{-\infty}^{+\infty}f(x)dx=\int_0^1kxdx=k/2$$
must equal 1. I.e. $k=2$.
A: Simpler way:
Since the graph is like a triangle and it's area should be 1, then 1 = (height * width) / 2, and so I have 1 = (1 * k1)/2 , 1 = k/2 , 2 = k

$$\frac{height * width}{2} = 1$$
$$\frac{k1 * 1}{2} = 1$$
  $$\frac{k}{2} = 1$$
  $${k} = 2$$

Alternatively, there is a more advanced way suggested by @Jonh

$f$ is the density of the continuous random variable $X$. Its
  distribution function is $F(x)=\int_{-\infty}^xf(x)dx$. You must have
  that the probability of the whole space $\Omega$ is 1 so
  $$P(\Omega)=P(X\in\mathbb{R})=\lim_{t\to+\infty}F(t)=\int_{-\infty}^{+\infty}f(x)dx=\int_0^1kxdx=k/2$$
  must equal 1. I.e. $k=2$.

and @user365239

I'm assuming that the $f$ you have written is a probability density
  fuction of a random variable $X$. A defining property is that $\int
> f(x) \; dx =1$ for all pdf's. In our case, $$ \int f(x) \; dx =
> \int_0^1 kx \; dx = \frac{k}{2} $$ and so $k$ must be equal to two.

