-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsearch.java
More file actions
39 lines (37 loc) · 950 Bytes
/
search.java
File metadata and controls
39 lines (37 loc) · 950 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
*
*/
package HashMap;
import java.util.*;
/**
* @author M.NAVEEN
RANDOM CODER'S
*
*/
public class search {
static HashMap<Integer,String> map;
static Scanner nav;
public search()
{ nav=new Scanner(System.in);
map=new HashMap<Integer,String>();
}
public static void main(String[] args)
{ new search();
map.put(1,"red");
map.put(2,"blue");
map.put(3,"yellow");
System.out.println("HashMap :"+map);
System.out.println("Enter to check if the Key is present :");
if(map.containsKey(nav.nextInt()))
System.out.println("Is present");
else
System.out.println("Not present");
System.out.println("Enter to check if the Value is present :");
if(map.containsValue(nav.next())) //if nav.nextInt() the output is "Value Not present"
{
System.out.println("Is present");
}
else
System.out.println("Value Not present");
}
}