Let $f\colon[0,2]\to\mathbb{R}$ be such that, $$f(x) = \begin{cases} 1 &\text{if $0 \le x \le 1$} \\ 2 &\text{if $1 < x \le 2$} \end{cases} $$ Show that $f$ is Riemann integrable on $[0, 2]$ and find $\int_0^2f(x)\space dx.$
Solution Let $P=\{0,\frac{2}{n},\frac{4}{n},...,1,...,2\}$ with $n=2k$. Then, $$U(P;f)-L(P;f)=\sum_{k=0}^{n}(M_{k}-m_{k})\frac{2}{n}.$$ From our construction, whereby our partition includes a point at $x=1$, we know $m_{k}=M_{k}$ for all $k$. Thus, the sum is zero, and the function is integrable. Clearly, the integral is 3.
A simpler partition might be $P_n = (0,1,1+{1 \over n}, 2)$.
Then $L(f,P_n) = 1+2(1-{1 \over n})$, $U(f,P_n) = 3$.
Then $\sup L(f,P_n) = 3 = \inf U(f,P_n)$.