-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayRandom.java
More file actions
31 lines (26 loc) · 850 Bytes
/
Copy pathArrayRandom.java
File metadata and controls
31 lines (26 loc) · 850 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
import java.util.*;
class ArrayRandom {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int i, n, search, flag = 0;
System.out.println("Enter the number of elements:");
n = sc.nextInt();
int[] a = new int[n];
System.out.println("Enter the elements");
for (i = 0; i < n; i++) {
a[i] = sc.nextInt();
}
System.out.println("Enter the element to be seached");
search = sc.nextInt();
for (i = 0; i < n; i++) {
if (a[i] == search) {
System.out.println("Element " + search + " found at " + i + " position");
flag = 1;
break;
}
}
if (flag == 0) {
System.out.println("Element " + search + " not found");
}
}
}