A big reason is the treatment of theses countries after the war. The Allies realized their mistake in WWI and did not want to repeat it.
They had the Marshall Plan in Europe to rebuild war stricken Europe and a three phase occupation policy in Japan to reform the government and economy and rebuild the economy. Both were given significant economic aid.
Another factor was the people of Germany and Japan. They have a history of industriousness, hardworking, prideful and innovative. That still remained. These were the same characteristics that led them to war. They were channeled toward rebuilding their country after the war.
Finally, there was the factor that many of the victors were spent by the end of the war. They did not receive aid. They had huge debts. Some of them were in decline before the war started and continued afterwards.