The "integration by parts" method can be seen as a form of inverse product rule for differentiation:
#int fg' dx = fg - int f'g dx#, where #f,g# functions of #x#.
Here, we see that #(e^x)' = e^x#, so this matches directly with
#int fg' dx# where #f(x) = x^2# and #g(x) = e^x#.
Therefore,
#int x^2e^xdx = x^2e^x - int 2xe^xdx#
Now, since #e^x# can be differentiated indefinitely without a change, we can apply this method again, differentiating repeatedly until the integrals are gone:
#int 2xe^xdx = 2xe^x - int 2e^xdx#
#=2xe^x -2inte^xdx#
#=2xe^x - 2e^x + c#
Now, we have to subtract this from the original #x^2e^x# (the #fg# part in our example) to get the final answer:
#intx^2e^xdx = x^2e^x -2xe^x + 2e^x +c = e^x(x^2 - 2x + 2) + c#
I did realize I said subtract, yet still put #+c# instead of #-c# at the end. That is because it's an arbitrary constant, and can be any real number, and in the end, most people use #+c# in their notation.