import java.util.Scanner;
import java.text.SimpleDateFormat;
import java.util.Date;
public class salary
{
public static void main(String[] args)
{
int n,sum=0,average=0,count1=0,count2=0;
System.out.println("How many people salary you want to enter" );
Scanner in = new Scanner(System.in);
n = in.nextInt();
String[] salary=new String[n];
int[] sal=new int[n];
for (int i=0;i<n;i++)
{
System.out.println("please enter salary with $ sign as prefix" );
salary[i]=in.nextLine();
}
for (int j=0;j<n;j++)
{
salary[j] = salary[j].replaceAll("[$]+", "0");
System.out.println(salary[j]);
sal[j]= Integer.parseInt(salary[j]);
//salary[j] = Integer.parseInt(salary[j].replaceAll("[$]+", " "));
sum=sum+sal[j];
}
average=sum/n;
for(int q=0;q<n;q++)
{
if (sal[q]>average)
{count1=count1+1;
}
else if (sal[q]<average)
{
count2=count2+1;
}}
System.out.println("The average is "+average);
System.out.println("The salary greater than average "+count1);
System.out.println("The salary less than average "+count2);
}
}
getting error and also for loop is not working properly
Exception in thread "main" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:592)
at java.lang.Integer.parseInt(Integer.java:615)
at salary.main(salary.java:34)
read a list of salary amounts that start with a dollar sign “$” and followed by a nonnegative number, save the valid salary inputs into an array and sort the salary in ascending order, calculate the average of the salary inputs, and count the number of inputs less than /greater than the average.