-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram26.java
More file actions
43 lines (27 loc) · 968 Bytes
/
Copy pathprogram26.java
File metadata and controls
43 lines (27 loc) · 968 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
40
41
42
43
// Take a number from the user and check whether it exists in the array.
import java.util.Scanner;
public class program26 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter 5 Array Elements : ");
int arr[] = new int[5];
for (int i = 0; i < 5; i++) {
arr[i] = sc.nextInt();
}
boolean found = false;
System.out.println("Enter Search Element : ");
int search = sc.nextInt();
for (int i = 0; i < 5; i++) {
if (arr[i] == search) {
found = true;
System.out.println("Element Found");
System.out.println("Index no. : " + i);
break;
}
}
if (!found) {
System.out.println("Element Not Found !!!");
}
sc.close();
}
}