import java.util.Scanner; //Write a program that reads an unspecified number of scores and, //determines how many scores are above or equal to the average and how many, //scores are below the average. Enter a negative number to signify the end of the, //input. Assume that the maximum number of scores is (10), public class Ok { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter Scores:(negative number signifies end):"); int scores[] = new int[10]; int numberofScores = 0; int average = 0; for (int i = 0; i < 10; i++) { scores[i] = input.nextInt(); if (scores[i] < 0) break; average += scores[i]; numberofScores++; } average /= numberofScores; int AboveOREqual = 0, below = 0; for (int i = 0; i < numberofScores; i++) { if (scores[i] >= average) { AboveOREqual++; } else { below++; } } System.out.println("\n Average of scores:" + average); System.out.println("Number of scores above or equal to average:" + AboveOREqual); System.out.println("Number of scores below average:" + below); }; };
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter