Answer to Question #322570 in Java | JSP | JSF for Nhm

Question #322570

Write a Java program to do the following

a) Read the names of employeeid, name and salary of all employees.

b) Check whether the given employeeid is present in the array,

if it is not, print the name of the employee and the employeeid.


1
Expert's answer
2022-04-02T09:58:52-0400
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner in = new Scanner(System.in);

        Map<Integer, String> empls = new HashMap<Integer, String>();

        empls.put(1, "Mark");
        empls.put(2, "German");
        empls.put(4, "Frank");
        empls.put(3, "Luck");

        int ser = in.nextInt();

        for(Map.Entry<Integer, String> item : empls.entrySet()){

            if(ser == item.getKey()){
                System.out.printf("ID: %d  Name: %s \n", item.getKey(), item.getValue());
            }

        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS