java - Scanner specifics -



java - Scanner specifics -

i making programme grades external file, find sum , average of them, , display that. in addition, programme stops when reaches zero. question when test if next number not zero, skips number , hence not utilize number in calculation. current approach is:

while ((current = infile.nextint()) != 0) { system.out.println(current); sum += current; numberofscores++; }

setting next int variable @ same time tested. while way works, there certainly must easier way done. there?

thanks in advance help --cheers

i'm little confused prompt- looking simplify approach, or able go on past zero?

either way, approach here little risky. begs programme crashes. i'd recommend among these lines, ensure there int.

while(infile.hasnextint()){ int tmp = infile.nextint(); system.out.println(tmp); sum += tmp; numberofscores++; }

if want, add together in code skip on 0s.

java java.util.scanner

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -