Answer to Question #298028 in Java | JSP | JSF for Seler

Question #298028

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.


1
Expert's answer
2022-02-15T13:58:00-0500
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();
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS