Question: Modify the AvgSalary code below to allow the user to set the counter value before entering into the loop. //Imports import java.util.Scanner; //Begin Class SalAvg

Modify the AvgSalary code below to allow the user to set the counter value before entering into the loop.

//Imports

import java.util.Scanner;

//Begin Class SalAvg

public class SalAvg {

//Begin Main Method

public static void main(String[] args) {

//Declarations

int salCnt = 0;

double salary = 0;

double tot = 0;

double salAvg = 0;

//New Scanner object

Scanner sc = new Scanner(System.in);

//While loop to find average

while (salCnt < 5) {

System.out.printf("Enter the salary/hr amount %d: $", salCnt + 1);

salary = sc.nextDouble();

tot += salary; //Add entry to running total

salCnt += 1; //Increment the counter

}

//Determine the average

salAvg = tot / salCnt;

//Output the average

System.out.printf("The average of the %d salaries is: $%.2f ", salCnt, salAvg);

}

} //End Class SalAvg

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!