Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how i call methods  RSS feed

 
ekte spiriopoulos
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

i have this on a class .How i call this method on the main ???what should i write on the main for calling it?
i want to call a seqsearch for int
and a seqsearch for string .How i call both?
 
Trung Hieu Hoang
Greenhorn
Posts: 12
AngularJS Java PHP
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As seqSearch is private, it's only possible if main is defined inside the same class.

 
Campbell Ritchie
Marshal
Posts: 55717
163
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trung Hieu Hoang wrote:As seqSearch is private, it's only possible if main is defined inside the same class. . . .
Disagree. I would suggest such a method should have public access, which will solve your problem.
 
ekte spiriopoulos
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:
Trung Hieu Hoang wrote:As seqSearch is private, it's only possible if main is defined inside the same class. . . .
Disagree. I would suggest such a method should have public access, which will solve your problem.


but on the key_1 and key_2 is underline like an error
MyUtils.seqSearch(f, key_1);
MyUtils.seqSearch(f, key_2);
 
Liutauras Vilda
Marshal
Posts: 4641
318
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And when you hover your mouse on the exclamation mark (most likely on the left of your IDE window), what does it say?

By the way, key_a variable naming does not follow Java naming convention. That should read as keyA in Java.
Missing curly braces also are not common in Java. Better do not omit ever.
 
Campbell Ritchie
Marshal
Posts: 55717
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I merged your stuff with the following thread. I hope that is okay by you.
 
ekte spiriopoulos
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
both in binary search how would it be ?
 
Les Morgan
Rancher
Posts: 768
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a binary search the data has to be ordered for it to be meaningful. You select half of the list. If the median is what you are looking for, then you are done, else if it is less than the target value, then you take the upper half as the list and repeat the search, if more than take the lower half and repeat the search. It is a recursive algorithm.
 
Campbell Ritchie
Marshal
Posts: 55717
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But what is the problem? You have a mysterious field called thesi, which I think ought not be there. What does it mean? Your indentation is hard to follow and will cause you no end of confusion becuase you are not putting {} around your control structures.
You have a class called Array (very bad name) which has name and aet (probably meaning age) fields, so it is poor design for them to have such checks outside their own class.Now use that in your loops
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Les Morgan wrote:It is a recursive algorithm.

Hmmm. It can be, but it doesn't have to be.

Although I have to admit, even I would code a binary search recursively.

Winston
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ekte spiriopoulos wrote:both in binary search how would it be ?

Ekte,

You appear to be firing off questions almost at random in the hope of finding some guidance; but it's a very bad way to learn.

My advice: Find a good book (this one is supposed to be quite good), or the Java Tutorials, read them thoroughly, and do all the exercises.
Because that's how you'll learn the language.

We're happy to help people who have problems with Java, but we're not meant to be your "online tutorial".

HIH

Winston
 
Campbell Ritchie
Marshal
Posts: 55717
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:. . . Find a good book (this one is supposed to be quite good), . . .
It is. Get a second‑hand copy and it will cost much less. But it doesn't (as far as I remember) tell you how to do linear search. (You are not doing a binary search.)

I think a few of these threads should be merged, since they are about the same things.
 
ekte spiriopoulos
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ekte spiriopoulos wrote: i write this .You talk about array right?
Winston Gutkowski wrote:
Les Morgan wrote:It is a recursive algorithm.

Hmmm. It can be, but it doesn't have to be.

Although I have to admit, even I would code a binary search recursively.

Winston
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ekte spiriopoulos wrote:i write this .You talk about array right?

No. Les's post mentioned 'recursion'.

He also explained exactly what a binary search does. Your code, if it worked - which it can't because it doesn't compile - appears to be a sequential search.

Winston
 
ekte spiriopoulos
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:
ekte spiriopoulos wrote:i write this .You talk about array right?

No. Les's post mentioned 'recursion'.

He also explained exactly what a binary search does. Your code, if it worked - which it can't because it doesn't compile - appears to be a sequential search.

Winston
i swear i cant understand nor learn something .i quit from this site thanks for your 'help' but i cant learn anything with your methods.
 
Trung Hieu Hoang
Greenhorn
Posts: 12
AngularJS Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:
Trung Hieu Hoang wrote:As seqSearch is private, it's only possible if main is defined inside the same class. . . .
Disagree. I would suggest such a method should have public access, which will solve your problem.

Indeed, public method should be better solution. I just tried to give answer based on existing code.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!