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
Post a Comment