To find E(X2), we can take the sum of all f(x)⋅X2. The integral is a useful tool to use when summing quantities over a continuous distribution.
E(X2) = ∫01f(x)X2dx=∫011⋅X2dx=31X301=31
We can compute E(X)2 in a similar way buy summing f(x)X and then squaring that result, but a simpler way would be to realize that the average result of a uniform distribution will just be its midpoint. Hence, E(X)2=(21)2=41