linear search

linear search

View Answers

November 30, 2008 at 11:38 PM

Hi friend,


Code to solve the problem :

public class LinearSearch
{


// Search "array" for the specified "key" value
public static boolean linearSearch( String array[][], int key1,int key2,String strMatch)
{
for ( int n = 0; n <array.length; n++ )
{
for(int m=0;m<array[n].length;m++)
{
if((key1==n) && (key2==m))
{
String str = array[n][m].substring(0,2);
if(str.equals(strMatch))
{
return true;
}
}
}
}

return false;
}


public static void main(String args[])
{

String Data[][] = new String[2][3];

Data[0][0] = "Hello"; //lastname
Data[0][1] = "World"; //firstname
Data[0][2] = "Roseindia"; //location

//Second row
Data[1][0] = "Xyz"; //lastname
Data[1][1] = "Abc"; //firstname
Data[1][2] = "India"; //location


int key1 = 1;
int key2 = 1;
String strmatch = "Ab";

if(linearSearch(Data,key1,key2,strmatch))
{
System.out.println("Item exists");
}
else
{
System.out.println("Item doesn't exists");
}

}
}

For any more problem on Java visit to :

http://www.roseindia.net/java/

Thanks









Related Tutorials/Questions & Answers:
linear search
linear search  write a program to find string using linear search
linear search - Java Beginners
linear search  How do i use a linear search for a 2 dimensional hard coded array? I need to check the first 2 letters in an item number... { // Search "array" for the specified "key" value public static
Advertisements
Linear search in java
Linear search in java In this section we will  know, what is linear search and how linear works. Linear search is also known as "sequential.... Linear search is a searching mechanism which search  key element
Linear Search in Java
Linear Search in Java In this section, we are going to find an element from an array using Linear Searching. Linear searching is a good way to find an element...(); } LinearSearch search = new LinearSearch(); System.out.print("Enter the element
Linear hashing
Linear hashing   hello,, What is linear hashing?   hii,ADS_TO_REPLACE_1 In linear hashing, the table is gradually expanded by splitting the buckets in order until the table has doubled its size
Linear Regression
Linear Regression  hi........ Can u give me a simple code for Linear Regression in java swings????????? thanks in advance plz reply
linear sorting
linear sorting  what is linear sorting? can any send me an example   Hi Friend, Try this: import java.util.*; class ArraySort{ public static void sortArray(int arr[]){ Arrays.sort(arr); System.out.println
ModuleNotFoundError: No module named 'linear'
ModuleNotFoundError: No module named 'linear'  Hi, My Python... 'linear' How to remove the ModuleNotFoundError: No module named 'linear'... to install padas library. You can install linear python with following command
Binary Search in Java
Binary Search in Java In this section, we are going to search an element from an array using Binary Search. The advantage of a binary search over a linear search is astounding for large numbers. It can be done either recursively
Linear and Non-Linear Data Structure in C
Linear Data Structure: Linear data structure is linear if element is adjacent... as its previous and next member. Example of Linear Data Structure Array Linked List Stack Queue Non- Linear Data Structure Non-Linear data
ModuleNotFoundError: No module named 'linear_algebra'
ModuleNotFoundError: No module named 'linear_algebra'  Hi, My... named 'linear_algebra' How to remove the ModuleNotFoundError: No module named 'linear_algebra' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'linear-regression'
ModuleNotFoundError: No module named 'linear-regression'  Hi, My... named 'linear-regression' How to remove the ModuleNotFoundError: No module named 'linear-regression' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'linear_series'
ModuleNotFoundError: No module named 'linear_series'  Hi, My... 'linear_series' How to remove the ModuleNotFoundError: No module named 'linear_series' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'linear-tsv'
ModuleNotFoundError: No module named 'linear-tsv'  Hi, My Python... 'linear-tsv' How to remove the ModuleNotFoundError: No module named 'linear-tsv' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'linear_binning'
ModuleNotFoundError: No module named 'linear_binning'  Hi, My... named 'linear_binning' How to remove the ModuleNotFoundError: No module named 'linear_binning' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'linear-reg'
ModuleNotFoundError: No module named 'linear-reg'  Hi, My Python... 'linear-reg' How to remove the ModuleNotFoundError: No module named 'linear-reg' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'linear-spider'
ModuleNotFoundError: No module named 'linear-spider'  Hi, My... 'linear-spider' How to remove the ModuleNotFoundError: No module named 'linear-spider' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'lsq_linear'
ModuleNotFoundError: No module named 'lsq_linear'  Hi, My Python... 'lsq_linear' How to remove the ModuleNotFoundError: No module named 'lsq_linear' error? Thanks   Hi, In your python environment you
Version of com.literatejava>linear-block-allocator dependency
List of Version of com.literatejava>linear-block-allocator dependency
ModuleNotFoundError: No module named 'complex-linear-network-analyzer'
ModuleNotFoundError: No module named 'complex-linear-network-analyzer' ...: ModuleNotFoundError: No module named 'complex-linear-network-analyzer' How to remove the ModuleNotFoundError: No module named 'complex-linear-network-analyzer' error
ModuleNotFoundError: No module named 'linear-algebra-ulloa'
ModuleNotFoundError: No module named 'linear-algebra-ulloa'  Hi...: No module named 'linear-algebra-ulloa' How to remove the ModuleNotFoundError: No module named 'linear-algebra-ulloa' error? Thanks   Hi
ModuleNotFoundError: No module named 'linear-combination-py'
ModuleNotFoundError: No module named 'linear-combination-py'  Hi...: No module named 'linear-combination-py' How to remove the ModuleNotFoundError: No module named 'linear-combination-py' error? Thanks   Hi
ModuleNotFoundError: No module named 'linear_congruences_riyadk'
ModuleNotFoundError: No module named 'linear_congruences_riyadk'  Hi...: No module named 'linear_congruences_riyadk' How to remove the ModuleNotFoundError: No module named 'linear_congruences_riyadk' error? Thanks  
ModuleNotFoundError: No module named 'salmon-linear-modeling'
ModuleNotFoundError: No module named 'salmon-linear-modeling'  Hi...: No module named 'salmon-linear-modeling' How to remove the ModuleNotFoundError: No module named 'salmon-linear-modeling' error? Thanks   Hi
ModuleNotFoundError: No module named 'simple-linear-algebra'
ModuleNotFoundError: No module named 'simple-linear-algebra'  Hi...: No module named 'simple-linear-algebra' How to remove the ModuleNotFoundError: No module named 'simple-linear-algebra' error? Thanks   Hi
ModuleNotFoundError: No module named 'sparse_linear_binning'
ModuleNotFoundError: No module named 'sparse_linear_binning'  Hi...: No module named 'sparse_linear_binning' How to remove the ModuleNotFoundError: No module named 'sparse_linear_binning' error? Thanks   Hi
ModuleNotFoundError: No module named 'woe-linear-bin'
ModuleNotFoundError: No module named 'woe-linear-bin'  Hi, My... named 'woe-linear-bin' How to remove the ModuleNotFoundError: No module named 'woe-linear-bin' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'complex-linear-network-analyzer'
ModuleNotFoundError: No module named 'complex-linear-network-analyzer' ...: ModuleNotFoundError: No module named 'complex-linear-network-analyzer' How to remove the ModuleNotFoundError: No module named 'complex-linear-network-analyzer' error
ModuleNotFoundError: No module named 'ie_mbdbl2018_dmburu_Linear_Congruency'
ModuleNotFoundError: No module named 'ie_mbdbl2018_dmburu_Linear_Congruency...: ModuleNotFoundError: No module named 'ie_mbdbl2018_dmburu_Linear_Congruency' How to remove the ModuleNotFoundError: No module named 'ie_mbdbl2018_dmburu_Linear
ModuleNotFoundError: No module named 'ie_mbdbl2018_ljv_linear_congruences'
ModuleNotFoundError: No module named 'ie_mbdbl2018_ljv_linear_congruences' ...: ModuleNotFoundError: No module named 'ie_mbdbl2018_ljv_linear_congruences' How to remove the ModuleNotFoundError: No module named 'ie_mbdbl2018_ljv_linear
search
search  how to develop search box and how to retrive data from database..   Please visit the following link: Search box
SEARCH
SEARCH  how can we do search in jsp...? option for search criteria like name and DOB...   Please visit the following links: http://www.roseindia.net/jsp/user-search.shtml http://www.roseindia.net/servlets/search.shtml
Binary Search in Java
Binary Search in Java is used to search an element from an array. Programmers opt for Binary search over linear search when it comes to large numbers. It can... the answer "Not Found".ADS_TO_REPLACE_1 Following is the example of Binary Search
Maven Dependency linear-block-allocator >> 3.6.10
You should include the dependency code given in this page to add Maven Dependency of com.literatejava >> linear-block-allocator version3.6.10 in your project
Maven Dependency linear-block-allocator >> 4.0.0
You should include the dependency code given in this page to add Maven Dependency of com.literatejava >> linear-block-allocator version4.0.0 in your project
What is Linear Tape Open(LTO)
and application of data. LTO or Linear Tape Open is one of the most promising storage... for data sharing. LTO or Linear Tape Open is the storage technology that addresses all...) and Quantum's DLT (Digital Linear Tape). Other big brands in the storage market were
Search
Search   Hi, I have a project in which I am trying to enter "Marathi" (Indian local language) data in JSP using JSTL and trying to search data... and tries to search then It shows no data from database
Maven Repository/Dependency: com.literatejava | linear-block-allocator
Maven Repository/Dependency of Group ID com.literatejava and Artifact ID linear-block-allocator. Latest version of com.literatejava:linear-block-allocator dependencies. # Version Release Date
gauss elimination of system of linear equations using java code
gauss elimination of system of linear equations using java code  Here is my code: import java.util.Scanner; import java.util.*; public class gausselimination { private static final double EPSILON = 1e-10
Search index
Search index  how to write code for advanced search button
Maven, Gradle, SBT, Ivy, Grape, Leiningen and Buildr Dependency for linear-block-allocator version 3.6.10
Maven, Gradle, SBT, Ivy, Grape, Leiningen and Buildr Dependency for linear... com.literatejava:linear-block-allocator:3.6.10 Java library in your project.. Maven, Gradle, SBT, Ivy, Grape, Leiningen and  Buildr Dependency for linear
Maven, Gradle, SBT, Ivy, Grape, Leiningen and Buildr Dependency for linear-block-allocator version 4.0.0
Maven, Gradle, SBT, Ivy, Grape, Leiningen and Buildr Dependency for linear... com.literatejava:linear-block-allocator:4.0.0 Java library in your project.. Maven, Gradle, SBT, Ivy, Grape, Leiningen and  Buildr Dependency for linear
Hibernate Search
Hibernate Search  Where to learn Hibernate Search module? Thanks   Hi, Check the tutorial: Hibernate Search - Complete tutorial on Hibernate Search Thanks
SEARCH AND SORT
SEARCH AND SORT  Cam any one provide me the code in java that : Program to search for MAX,MIN and then SORT the set using any of the Divide and conquer method
SEARCH PAGE
SEARCH PAGE  search page:option for search criteria like name and DOB will be asked.on entering the detail,data matching search criteria will be displayed..criteria can be both or any one of them.. can you send code
php search variable
php search variable  Search variable in PHP
search for a name
search for a name  Search for a name Write a program to accept an array of names and a name and check whether the name is present in the array. Return the count of occurrence. Use the following array as input {?Dave?, ?Ann
Search Engine
Search Engine  I have gone through the below mentioned link document to create search engine and fetch the data from mysql database.But i am getting errors. http://www.roseindia.net/sql/mysql-table/sql-search.shtml Error: Notice
search program
search program  i m writing program which takes company names from databse...serch on google...n try to find the best match WEBSITE...of company name... links after google search...plzz help
Google Search
Google Search  I have a textbox and submit button in my JSP page. On giving word in the textbox and click submit it should redirct to google search page and fetch all the results based on my input word automatically. JSP/Servlet

Ads