Knowee
Questions
Features
Study Tools

Write a Java program that reads an unspecified number of scores anddetermines how many scores are above or equal to the average, and how many scoresare below the average. Enter a negative number to signify the end of the input. Assumethe maximum number of scores is 100.

Question

Write a Java program that reads an unspecified number of scores anddetermines how many scores are above or equal to the average, and how many scoresare below the average. Enter a negative number to signify the end of the input. Assumethe maximum number of scores is 100.

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a simple Java program that fulfills your requirements:

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int[] scores = new int[100];
        int num = 0;
        double sum = 0;
        int count = 0;

        System.out.println("Enter scores (negative number signifies end):");

        // Read scores and calculate sum
        for (int i = 0; i < 100; i++) {
            num = input.nextInt();
            if (num < 0) 
                break;
            scores[i] = num;
            sum += num;
            count++;
        }

        // Calculate average
        double average = sum / count;

        int aboveOrEqual = 0, below = 0;
        for (int i = 0; i < count; i++) {
            if (scores[i] >= average)
                aboveOrEqual++;
            else
                below++;
        }

        System.out.println("Average is " + average);
        System.out.println("Number of scores above or equal to the average: " + aboveOrEqual);
        System.out.println("Number of scores below the average: " + below);
    }
}

This program reads scores from the user until a negative number is entered. It calculates the sum of the scores and the average. Then it counts how many scores are above or equal to the average and how many are below the average. Finally, it prints out the average, the number of scores above or equal to the average, and the number of scores below the average.

This problem has been solved

Similar Questions

Write a Java program that determines a student’s grade. The program will read three types ofscores(quiz, mid-term, and final scores) and determine the grade based on the following rules: -if theaverage score >=90% =>grade=A -if the average score >= 70% and <90% => grade=B -if theaverage score>=50% and <70% =>grade=C -if the average score<50% =>grade=F

Example 1 int x = 10; // Variable named x with the data type int with initial value of 10. if (x > 5) { // Begins an if statement that checks the condition inside the parentheses: x > 5. // If the condition is true, the block of code inside the curly braces {} will be executed. System.out.println("x is greater than 5"); // Display "x is greater than 5" to the console if the condition if statement is true. } What will be the output if the user enters negative scores for all subjects? (Refer to Code 1) Group of answer choices Good Needs improvement Outstanding! Very Good!

Example 1 int x = 10; // Variable named x with the data type int with initial value of 10. if (x > 5) { // Begins an if statement that checks the condition inside the parentheses: x > 5. // If the condition is true, the block of code inside the curly braces {} will be executed. System.out.println("x is greater than 5"); // Display "x is greater than 5" to the console if the condition if statement is true. } What is the highest possible average score for which the program outputs "Outstanding!"? (Refer to Code 1) Group of answer choices 95 80 90 85

Counting Positive and Negative NumbersA teacher wants to analyze the performance of students in a test. The test scores for the class of 20 students are given. Write a program that counts the number of positive and negative scores.Constraints:NAExample:Sample Input:102030-40-50-60-70-80-90-100110120130140150160170180190200Sample Output:Positive 13Negative 7Explanation:From the sample input--> Test score of 20 students Output-->13 Positive scores                  7 Negative scores

Code 1 Copy this code, compile and run it so you can answer the questions. import java.util.Scanner; public class UserGradingSystem { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // Prompt user to enter scores for three subjects System.out.print("Enter math score: "); int mathScore = scanner.nextInt(); System.out.print("Enter science score: "); int scienceScore = scanner.nextInt(); System.out.print("Enter English score: "); int englishScore = scanner.nextInt(); // Calculate the average score int averageScore = (mathScore + scienceScore + englishScore) / 3; // Determine the overall grade if (averageScore >= 90) { System.out.println("Outstanding!"); } else if (averageScore >= 80) { System.out.println("Very Good!"); } else if (averageScore >= 70) { System.out.println("Good"); } else { System.out.println("Needs improvement"); } } } What if the user enters "85," "90," and "88," but mistakenly adds a semicolon after the English score, entering "88;"? (Refer to Code 1) Group of answer choices The program outputs "Needs improvement" for the invalid score. The program handles it gracefully, treating the input as valid. The program outputs "Outstanding!" for the valid scores. The program crashes with a runtime exception.

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.