linear search in java

Solutions on MaxInterview for linear search in java by the best coders in the world

showing results for - "linear search in java"
Aliyah
03 Apr 2017
1public static int linear(int[] arr, int keyValue)
2{
3  int pos = -1; 
4
5    for (int i = 0; i < arr.length; i++)
6    {
7        if (arr[i] == keyValue)
8        {
9            pos = i;
10            break;
11        }
12	}
13	return pos;
14}
Salvatore
13 Jan 2018
1public class LinearSearchExample
2{
3   // here function returns index of element x in arrLinear
4   static int searchNumber(int[] arrLinear, int key)
5   {
6      int num = arrLinear.length;
7      for(int a = 0; a < num; a++)
8      {
9         // here we are returning the index of the element if found
10         if(arrLinear[a] == key)
11            return a;
12      }
13      // here we are returning -1 if element is not found
14      return -1;
15   }
16   public static void main(String[] args)
17   {
18      int[] arrLinear = {15, 25, 35, 55, 75, 95};
19      int key = 55;
20      int output = searchNumber(arrLinear, key);
21      if(output == -1)
22      {
23         System.out.println("Sorry!!Element is not present");
24      }
25      else
26      {
27         System.out.println("Element is present at index " + output);
28      }
29   }
30}
queries leading to this page
how to do linear search in javajava linear scanslinear search in java using string elementsjava linear search phone java program for linear searchlinear search program in javawhat is linear search javalinear search in java without functionlinear search for string in javalinear swarch in javalinear searching in javalinear search and javalinear search in java using arrayhow to do a linear searc in javalinear search in javalinear search in java 3fhow can user search in javalinear search method javalinear search in array javalinear search with flag javagive implementation of linear search in javais java linear 3fwhat is linear search in javaliner search in javajava linear search programsearch element in javaint linearsearch 28int arr javalinearsearch method javaprogram to implement linear search in javalinear search method java examplelinear seaarch in javalinear search in java programjava searching programjava 3binear searchjava array linear searchhow to do a linear search in javalinear search algorithm java methodlinear search java examplelinear search array in javalinear search string array javasearching in array in javalinear search array javalinear search string javahow to write a linear search in java with a stringprograms based on linear search for class 10write a java program to implement linear search in a given array of elements 3fjava built in linear searchjava implementation of linear searchhow to write linear search in javalinear search programjava code searchlinear seaarch javajava program on linear searchjava linear scanlinear search javatpointhow to perform linear search in vector in jhavalinear search using javalinear search in java with positionlinear search code in javalinear seach in javalinear search algorithm for string in javajava program of linear search using arraysearch code in javahow to write a linear search in javaserach a no in array in javalinear search recursive javalinear search in java best example programlinear search code javabest use for linear search in javalinear search in javaliinear search in javalinear serach in javawhat is linear search good for javalinear search javaexample of linear search in javachar sort using lenear searchlinear search java programsbuilt in java linear searchhow to make linear search function in javasearching code in javalinear search algorithm javalinear search javaarray search with linear java codelinear search algorithm in javajava linear searchlinear search on java list linear search java programsearch courses in javalinear search c 2b 2b algortihmlinear search in java