-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTraining.java
More file actions
32 lines (29 loc) · 918 Bytes
/
Training.java
File metadata and controls
32 lines (29 loc) · 918 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
import java.util.Scanner;
public class Training {
public static Boolean linearSearch(int[] arr,int key,int size){
for(int i=0;i<size;i++){
if(arr[i]==key){
return true;
}
}
return false;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the size of array");
int size = sc.nextInt();
int[] arr = new int[size];
System.out.println("Enter array Element");
for(int i=0;i<size;i++){
arr[i]=sc.nextInt();
}
System.out.println("Enter the element to find");
int key=sc.nextInt();
if(linearSearch(arr, key, size)){
System.out.println("Element present in the array");
}
else{
System.out.println("Element not present");
}
}
}