Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. import java.util.*;
  2. public class LinearSearch {
  3. public static void main(String args[])
  4. {
  5. Scanner sc= new Scanner(System.in);
  6. boolean flag=false;
  7. int[] a={22,33,44,55,11,21,77};
  8. System.out.println("enter the element to search in the array");
  9. int s=sc.nextInt();
  10. for(int i=0;i<a.length;i++)
  11. {
  12. if(s==a[i])
  13. {
  14. flag=true;
  15. System.out.println("the element is present at position"+ i);
  16. break;
  17. }
  18.  
  19. }
  20. if(flag==false)
  21. {
  22. System.out.println("the elemt does not exist");
  23. }
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement