Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- class LinearSearch{
- public static void main(String args[]){
- boolean flag = false;
- Scanner sc = new Scanner(System.in);
- System.out.println("Enter the size of array");
- int n = sc.nextInt();
- System.out.println("Enter the array");
- int arr[] = new int[n];
- for(int x = 0; x<n; x++){
- arr[x] = sc.nextInt();
- }
- int key = sc.nextInt();
- for(int x=0; x<n; x++){
- if(arr[x] == key){
- flag = true;
- }
- }
- if(flag == true){
- System.out.println("Key found");
- }
- else{
- System.out.println("Key not found");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment