# Answer to Question #22662 in Java | JSP | JSF for shalenee

Question #22662

Write a program that calculates the minimum, maximum, average and standard deviation (s) of the exam score in a subject. The program will accepts the score and quit if negative score is enter.

Expert's answer

import java.util.ArrayList;

import java.util.Scanner;

public class Average {

public static void main(String... args){

ArrayList<Integer> scores= new ArrayList<Integer>();

Scanner scanner = newScanner(System.in);

int sum = 0;

int max = Integer.MIN_VALUE;

int min = Integer.MAX_VALUE;

while (true) {

System.out.print("Enter scores >");

int n =scanner.nextInt();

if (n < 0) {

break;

}

if (n > max) {

max= n;

}

if (n < min) {

min= n;

}

sum += n;

scores.add(n);

}

System.out.println("min is: " + min);

System.out.println("man is: " + max);

float avg = (float) (sum) /(scores.size());

System.out.println("averageis :" + avg);

float stddevSum=0;

for (int index = 1; index < scores.size(); index++) {

stddevSum += (avg- scores.get(index))*(avg - scores.get(index));

}

double stddev =Math.sqrt(stddevSum / (scores.size()-1));

System.out.println("stddevis :" + stddev);

}

}

import java.util.Scanner;

public class Average {

public static void main(String... args){

ArrayList<Integer> scores= new ArrayList<Integer>();

Scanner scanner = newScanner(System.in);

int sum = 0;

int max = Integer.MIN_VALUE;

int min = Integer.MAX_VALUE;

while (true) {

System.out.print("Enter scores >");

int n =scanner.nextInt();

if (n < 0) {

break;

}

if (n > max) {

max= n;

}

if (n < min) {

min= n;

}

sum += n;

scores.add(n);

}

System.out.println("min is: " + min);

System.out.println("man is: " + max);

float avg = (float) (sum) /(scores.size());

System.out.println("averageis :" + avg);

float stddevSum=0;

for (int index = 1; index < scores.size(); index++) {

stddevSum += (avg- scores.get(index))*(avg - scores.get(index));

}

double stddev =Math.sqrt(stddevSum / (scores.size()-1));

System.out.println("stddevis :" + stddev);

}

}

Need a fast expert's response?

Submit orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment