Answer:
k = 40 N/m
Step-by-step explanation:
A spring's energy is given:

U is the energy in the spring, k is the spring constant and x is the spring displacement.
We are told that the spring stores 5J of energy, therefore, U = 5J. We are also told that the spring is compressed by 0.5m, so the spring x = 0.5m

k = 40 N/m
Hope this helps!