a. Write a Java application that does the following: Reads a positive integer from user represents number of the employees in a company. Reads salaries of the employees from user (user should enter the salaries, which are real numbers, in one line separated by spaces). Calculates and prints the following statistical measures: The mean of salaries of the employees (rounded to 2 decimal places). The standard deviation of salaries of the employees (rounded to 2 decimal places). b. Give the exact output of your application. Provide a snapshot representing the exact output of any values from your choice. Hints: There is at least one employee in the company. You could assume that user will insert valid data. Read about "the mean" and "the standard deviation" in any "statistics" book, or search the internet in order to know how to calculate them. Sample Input: Enter number of the employees in the company: 5 Enter their salaries: 900 851.75 915.25 700 800.5 Sample Output: The mean of salaries of the employees is: 833.50 The standard deviation of salaries of the employees is: 77.91

* my query is how i can make first loop store the values in an array, and use the array's values in the second loop. please help!

import java.util.*;

public class Employee {

public static void main(String[] args ) {

int employNumber;

double salary = 0 , sum = 0 , sumsq = 0;

double mean = 0 , variance, stanDev;

Scanner input = new Scanner( System.in );System.out.print("Enter Number Of The Employees In The Company: ");

employNumber = input.nextInt();

System.out.print("Enter Their Salaries: ");

double [] array ; double num=0;

array = new double[employNumber];

double [] arrayM = new double[employNumber];

for (int count=1 ; count <= array.length ;count++){

salary = input.nextDouble();

sum += salary;

}mean = sum / employNumber;

for (int i=0; i<= array.length; i++) {

sumsq = (Math.pow((salary - mean), 2));

}

variance = (float) sumsq / (employNumber);

stanDev = Math.sqrt(variance);

System.out.println();

System.out.printf("The Mean Of Salaries Of The Employees is %.2f\n : " , mean);

System.out.printf("The Standard devaition Of Salaries Of The Employees is %.2f\n : ",stanDev );

}

}

To store values in an array use something like a[i] = x;

To read a value from an array use something like

x = a[i];

Now, it's your homework not mine so I think the rest is up to you.

well, I am not able to store values from one for loop and how can I use it in another for loop, please guide me.

message edited by s.gul

Ask Your Question

Weekly Poll

Do you think Google should sell budget phones in the US?

Discuss in The Lounge

Poll History