Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program in java using arrays to calculate mean, variance and standard de

ID: 3640660 • Letter: W

Question

Write a program in java using arrays to calculate mean, variance and standard deviation
of numbers. You should prompt ask the user how many numbers he/she wants to enter.
The user should not be able to enter a negative number. When user provided you with a
positive number, you should prompt as many times as the given number to enter numbers
and store them all in an array. Your program should then show the mean, variance and
standard deviation of these numbers
Example:
Output: How many numbers do you want to enter?
User enters : -1
Output: Your choice should be a positive number. How many numbers do you want to
enter?
User enters : 3
Output: Please enter number 1:
User enters 4
Output: Please enter number 2:
User enters 7
Output: Please enter number 3:
User enters 10
The mean of these numbers is 7.000
Variance of these numbers is 6.000
Standard deviation of these numbers is 2.4494

**Mean of ‘n’ numbers (say three numbers n1, n2, n3) = sum of numbers/nor (n1+n2+n3)/3

Variance= mean of squared deviations of a variable from the total mean. Say mean of three numbers n1, n2 and n3= N then variance ‘V’=[ (n1-N)2+ (n2-N)2+ (n3-N)2] /3

Standard deviation= square root of variance 

Explanation / Answer

DONT FORGET TO RATE LIFESAVER!!

public class MenaVarianceDeviation {

    public static void main(String[] args) {

        java.util.Scanner scan = new java.util.Scanner(System.in);
        double mean = 0;
        double variance = 0;
        double deviation = 0;
        double[] numbers;
        int inputValue = 0;
        boolean validInput = false;
       
        do {
            System.out.println("How many numbers do you want to enter?");
            System.out.print("User enters: ");
            inputValue = Integer.parseInt(scan.nextLine());
            if (inputValue <= 0)
                System.out
                        .print("Your choice should be a positive number greater than zero.");
            else
                validInput = true;

        } while (!validInput);
       
        numbers = new double[inputValue];
        for (int i = 0; i < numbers.length; i++) {
            System.out.print("Please enter number " + (i + 1) + ": ");
            numbers[i] = Integer.parseInt(scan.nextLine());
            mean = mean + numbers[i];
        }

        mean = mean / numbers.length;
        System.out.println("The mean of these numbers is " + (mean));
        for (int i = 0; i < numbers.length; i++) {
            variance = variance + (numbers[i] - mean) * (numbers[i] - mean);
        }       
        variance = variance / numbers.length;
        System.out.println("The variance of these numbers is " + variance);
       
        deviation = Math.sqrt(variance);
        System.out.println("The Standard Deviation of these numbers is "+ deviation);

    }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote