A stick of length 1 is broken at a random location. Let $X$ be the length of the longer piece. what is $\mathbb{E}(X^2) ?$ Let $U$ denote the random location where the stick is broken. Then $U \sim$ Unif $[0,1] .$ since $X$ is the bigger broken piece
$g(u)=\max (u, 1-u)=\left\{\begin{array}{ll}1-u, & \text { if } u<1 / 2 \\ u, & \text { if } u \geq 1 / 2\end{array}\right.$ $\mathbb{E}(X)=\mathbb{E} g(U)=\int_{0}^{1 / 2}(1-u) d u+\int_{1 / 2}^{1} u d u=\frac{3}{4}$
I managed to calculate $\mathbb{E}(X)$ but not sure about how to calculate $\mathbb{E}(X^2)$ Is that $\int_{0}^{1 / 2}(1-u)^2 d u+\int_{1 / 2}^{1} u^2 d u$
Since $$X = g(U) = \max(U, 1-U),$$ we simply have $$X^2 = \left(\max(U, 1-U)\right)^2 = \max(U^2, (1-U)^2),$$ hence $$\operatorname{E}[X^2] = \int_{u=0}^{1/2} (1-u)^2 \, du + \int_{u=1/2}^1 u^2 \, du,$$ which is what you wrote.