java - Possible to loop through scanner input? -



java - Possible to loop through scanner input? -

i've started learning java , can't seem find way utilize loop simple user input. let's have come in unknown number of hw scores, don't know until user enters in. problem have add together scores user entered. how go looping scanner portion of problem.

import java.util.scanner; public class homeworkcalculator { public static void main(string[] args) { scanner scanner = new scanner(system.in); system.out.println("please come in homework scores:"); double hwscores = scanner.nextdouble(); //how can loop through number of homework added on plus //add sum , find average?

try using while loop

scanner scanner = new scanner(system.in); double total = 0.0; int count = 0; while (true) { system.out.println("please come in homework scores:"); double hwscores = scanner.nextdouble(); if (hwscores < 0) break; total += hwscores; count++; } system.out.println ("avg score " + (total / (double (count)));

java

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

ubuntu - Bash Script to Check That Files Are Being Created -