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

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -