KnowledgeBoat Logo
|

Computer Applications

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:

TraineeManagerChefManagerDirectorManager

Input: Manager Output: 3

Java

Java Arrays

5 Likes

Answer

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

Output

BlueJ output of 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: Input: Manager Output: 3

Answered By

4 Likes


Related Questions