944,124 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 8769
  • Java RSS
Oct 10th, 2004
0

Linear Search

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
salmanrauf is offline Offline
2 posts
since Oct 2004
Oct 11th, 2004
0

Re: Help

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
Reputation Points: 25
Solved Threads: 10
Practically a Master Poster
freesoft_2000 is offline Offline
623 posts
since Jun 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: If Else Loops
Next Thread in Java Forum Timeline: writting screen saver program using J2ME





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC