English

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 - Computer Applications

Advertisements
Advertisements

Question

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

Code Writing
Advertisements

Solution

import java.util.Scanner;

public class EmployeeSearch {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        String[] designation = new String[100];

        System.out.println("Enter the designations of 100 employees:");
        for (int i = 0; i < 100; i++) {
            designation[i] = sc.nextLine().trim();
        }

        System.out.println("Enter the designation to count:");
        String target = sc.nextLine().trim();

        int count = 0;
        for (int i = 0; i < 100; i++) {
            if (designation[i].equalsIgnoreCase(target)) {
                count++;
            }
        }

        // Fixed the incomplete line from your image here:
        System.out.println("Total employees with designation \"" + target + "\": " + count);

        sc.close();
    }
}
shaalaa.com
  Is there an error in this question or solution?
2025-2026 (March) Official Board Paper
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×