-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumbertobesearches.java
43 lines (39 loc) · 1.25 KB
/
numbertobesearches.java
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
40
41
42
43
import java.util.Scanner;
public class numbertobesearches {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("enter size of the array");
int n = sc.nextInt();
int[] arr = new int[n];
System.out.println("enter " + n + " elements ");
for (int i = 0; i < arr.length; i++) {
arr[i] = sc.nextInt();
}
int [] freq = makefrequencies(arr);
System.out.println("enter the no of queries");
int q = sc.nextInt();
while (q>0) {
System.out.println("enter the number to be searched");
int x = sc.nextInt();
if (freq[x] >0) {
System.out.println("yes");
} else {
System.out.println("no");
}
q--;
}
}
static void print (int [] arr) {
for (int i =0; i< arr.length; i++) {
System.out.print(arr[i] + " ");
}
System.out.println();
}
static int [] makefrequencies (int [] arr ) {
int [] frequency = new int [100005];
for (int i =0; i < arr.length;i++) {
frequency[arr[i]]++;
}
return frequency;
}
}