Write a java program to find the average of several scores read by the user from keyboard, the program should stop accepting scores when the user enters a negative score, and then it displays the average for the scores
import java.util.Scanner; public class AverageScore { public static void main(String[] args) { Scanner in = new Scanner(System.in); double total = 0, count = 0, score; while (true) { System.out.print("Enter a score(negative score to stop): "); score = in.nextDouble(); if (score < 0) break; ++count; total += score; } System.out.println("Average score is " + (total / count)); } }
Get Answers For Free
Most questions answered within 1 hours.