Linear Search

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2004
Posts: 2
Reputation: salmanrauf is an unknown quantity at this point 
Solved Threads: 0
salmanrauf salmanrauf is offline Offline
Newbie Poster

Linear Search

 
0
  #1
Oct 10th, 2004
Hi this is Salman.I am having a problem is linear search.The program doesnt compile giving the error "No method found matching linsearch".My code is
class search{
public static void main(String args[]){
int A[]=new int[1000];
for(int i=0;i<A.length;i++){
A[i]=(int) (1000*Math.random() +1);
System.out.println(linSearch(799, A[i]));
}
}
}
class searching{
public static int linSearch (int target, int [] list)
{
int location = -1, i = 0;
boolean found = false;
while (!found && i < list.length)
{
if (list [i] == target)
found = true;
else
i++;
}
if (found)
{
location = i;
}
return location;
}
}
Please tell me what to do
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 609
Reputation: freesoft_2000 is an unknown quantity at this point 
Solved Threads: 8
freesoft_2000 freesoft_2000 is offline Offline
Practically a Master Poster

Re: Help

 
0
  #2
Oct 11th, 2004
hi everyone,
You need to declare an instance of the class containing the function
like this

searching a = new searching();
System.out.println(a.linSearch(799, A[i]));

Yours Sincerely

Richard West
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC