Write a program in java.io package to take a name(String) and salary(double) of 15 persons then display the name and salary and also display the average salary employees are getting.
import java.util.*;
class App {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String names[] = new String[15];
double salaries[] = new double[15];
double salariesTotal = 0;
for (int i = 0; i < names.length; i++) {
System.out.print("Enter employee name " + (i + 1) + ": ");
names[i] = in.nextLine();
System.out.print("Enter employee salary " + (i + 1) + ": ");
salaries[i] = in.nextDouble();
salariesTotal += salaries[i];
in.nextLine();
}
System.out.println();
for (int i = 0; i < names.length; i++) {
System.out.println("Enter employee name: " + names[i]);
System.out.println("Enter employee salary: " + salaries[i]);
}
double averageSalary = salariesTotal / 15.0;
System.out.printf("The average salary employees: %.2f\n", averageSalary);
in.close();
}
}
Comments
Leave a comment