Let b=speed of boat and c= speed of current. Time to go upstream against the current is 40/(b-c). Time to go downstream with the current is 42/(b+c). So 40/(b-c)=42/(b+c)=3. Take the first pair of expressions: 40(b+c)=42(b-c) (cross-multiplying); 40b+40c=42b-42c; 82c=2b, making b=41c mph.
Also, 40/(b-c)=3, 40=3b-3c=123c-3c=120c, making c=40/120=1/3 mph.
Check that this is satisfied in 42/(b+c)=3: 42=3b+3c=123c+3c=126c, making c=42/126=1/3 mph.