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

Question #298732

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();

}

}

Do this coding without using array and printf


1
Expert's answer
2022-02-18T07:31:28-0500
import java.util.*;


class App {


	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String ouput = "";
		double salariesTotal = 0;


		for (int i = 0; i < 15; i++) {
			System.out.print("Enter employee name " + (i + 1) + ": ");
			String name = in.nextLine();
			System.out.print("Enter employee salary " + (i + 1) + ": ");
			double salary = in.nextDouble();
			ouput += "Employee name " + (i + 1) + ": " + name + "\n";
			ouput += "Employee salary " + (i + 1) + ": " + salary + "\n";
			salariesTotal += salary;
			in.nextLine();
		}
		System.out.println(ouput);
		double averageSalary = salariesTotal / 15.0;
		System.out.println("The average salary employees: " + 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