Reduce the number of loops

Reduce the number of loops, from 2 to 1, in showResult()