4
Write a program to accept the designations of 100 employees in a single dimensional array. Accept the designation from the user and print the total number of employees with the designation given by the user as input.
Example:
| Trainee | Manager | Chef | Manager | Director | Manager |
Input: Manager Output: 3
Show SolutionHide Solution↓
import java.util.Scanner;
class EmployeeDesignation
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
String desig[] = new String[100];
int i, count = 0;
String search;
for(i = 0; i < 100; i++)
{
System.out.print("Enter designation: ");
desig[i] = sc.nextLine();
}
System.out.print("Enter designation to search: ");
search = sc.nextLine();
for(i = 0; i < 100; i++)
{
if(desig[i].equalsIgnoreCase(search))
count++;
}
System.out.println("Total employees with designation " + search + ": " + count);
}
}
