Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class LinearSearch {
- public static void main(String args[])
- {
- Scanner sc= new Scanner(System.in);
- boolean flag=false;
- int[] a={22,33,44,55,11,21,77};
- System.out.println("enter the element to search in the array");
- int s=sc.nextInt();
- for(int i=0;i<a.length;i++)
- {
- if(s==a[i])
- {
- flag=true;
- System.out.println("the element is present at position"+ i);
- break;
- }
- }
- if(flag==false)
- {
- System.out.println("the elemt does not exist");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement