The quote is from Hermann Hesse's book Siddhartha:
Kamaswami, the merchant: "Yes indeed. And what is it now what you've got to give? What is it that you've learned, what you're able to do?"
Siddhartha: "I can think. I can wait. I can fast."
Kamaswami: "That's everything?"
Siddhartha: "I believe, that's everything!"
Kamaswami: "And what's the use of that? For example, the fasting-- what is it good for?"
Siddhartha: "It is very good, sir. When a person has nothing to eat, fasting is the smartest thing he could do. When, for example, Siddhartha hadn't learned to fast, he would have to accept any kind of service before this day is up, whether it may be with you or wherever, because hunger would force him to do so. But like this, Siddhartha can wait calmly, he knows no impatience, he knows no emergency, for a long time he can allow hunger to besiege him and can laugh about it. This, sir, is what fasting is good for."
You can read the full chapter here: Siddhartha by Hermann Hesse