Don't write System.exit(). Least of all where you put it; your program is about to terminate normally anyway.
Lat's have some guesses about what's gone wrong. Is your loop running a different number of times from what you expected, as Junilu has hinted? Are you entering small numbers and getting an average of 0?