Taking x and y as the number of hours Josh swims each style, we have that:

We also know that he swins the same distance doing each style, it means that the product of 8 times x equals the product of 6 times y (the product of the speed times the time is the distance):

Use this equation to write one of the variables in terms of the other variable:

Now, use this expression in the first equation, write it in terms of the same variable (y) and solve:

Using this value, we can find x:

Use these values to find the distance swum doing each style and then add the distances:

He swam 24 meters.