Since we are talking for a right triangle and AB is the longer side , we conclude that AB is the hypotenuse
of the triangle.
So
AC = x
BC = x- 8
AB = x + 8
Then applying the Pythagorean Theorem we have AB2 = AC2 + BC2
or equivalently ( x + 8 )2 = x2 + ( x - 8 )2
x2 + 16 x + 64 = x2 + x2 - 16x + 64
32 x = x2
x (32 - x ) = 0
x= 32
Hence AC = 32
BC = 24
AB = 40