Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class LinearSearchIA{
- public static void main(String[] args) {
- int data[]={1,2,3,4,5};
- int element=3;
- int loc=0;
- boolean x=false;
- while (loc<data.length-1) {
- if(data[loc] == element){
- x=true;
- break;
- }
- loc++;
- }
- if(x){
- System.out.print("Location of array is "+(loc+1));
- }else{
- System.out.print("Location of array is "+x);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement