Start by letting the speed of the slower train be s km/hr. The speed of the other train is therefore s + 5 km/hr
Their relative speed (that is the speed of one as seen by the other) is the sum of these two; namely: 2s + 5 km/hr.
After two hours they will have travelled closer to each other by a distance (2s + 5)*2 km (because distance = speed*time). Since they started 340km apart and are now only 30km apart, the combined distance they have travelled is 340 - 30 = 310 km. So, we must have:
(2s + 5)*2 = 310
2s + 5 = 155
2s = 150
s = 75 km/hr
And the faster train's speed is 75+ 5 = 80 km/hr
(Edited to correct silly mistake!)