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.
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());
}
}
}
}
Comments
Leave a comment