Q:

Java Program to implement Linear Search

0

Program to implement Linear Search.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

public class demo1{    
public static int linearSearch(int[] arr, int key){    
        for(int a=0;a<arr.length;a++){    
            if(arr[a] == key){    
                return a;    
            }    
        }    
        return -1;    
    }    
    public static void main(String arr[]){    
        int[] arr1= {10,20,30,50,70,90};    
        int key = 70;    
        System.out.println(key+" is found at index: "+linearSearch(arr1, key));    
    }    
}  

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now