Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2007

Tip: Looking for answers? Try searching our database.

how to call a function

Thread view: 
dan - 16 Oct 2007 15:00 GMT
Hello, completely new to Java. I want to sort the values inside of
array1[0].

array1 is : array1 = new int [2][50].

public void sort(){
  //code in here sorts the values
}

QUESTION: How do I call the sort function?? In C, I would do
sort(array1[0]) and it would work. In java, it gives me error saying
"the method sort in __ is not applicable for the arguments (int)" .

Can someone help me make the call to sort() ?

Thanks!
Ingo Menger - 16 Oct 2007 16:06 GMT
> Hello, completely new to Java. I want to sort the values inside of
> array1[0].
[quoted text clipped - 11 lines]
>
> Can someone help me make the call to sort() ?

Your declaration of sort allows only one possible call: sort()
If you want to pass an array to sort, you must declare it
appropriately:
 public void sort(int[] arrayToSort) {
   ...
 }
Lew - 16 Oct 2007 16:12 GMT
> Hello, completely new to Java. I want to sort the values inside of
> array1[0].
[quoted text clipped - 10 lines]
>
> Can someone help me make the call to sort() ?

Such a call
 sort( stuff [0] )
passes ( stuff [0] ), that is, the zeroth element of stuff,

The error message that you paraphrase refers to a declaration you failed to
show us, that of array1.  (Incidentally, names that reflect implementation,
like "array1", "string3" and the like, should be more descriptive and less
tied to the specifics of their implementation.)

The error message tells you that you tried to pass an 'int' to the method
'sort()'.  Since you say that you passed 'array1[0]' to 'sort()', then
'array1[0]' must be an 'int'.  That means that 'array1' is an 'int []', which
also implies that you cannot have assigned an 'int [] []' to it, despite your
claim otherwise.

The best way to resolve the inconsistencies in your presentation is to provide
a complete code example, literally an "SSCCE"
<http://www.physci.org/codes/sscce.html>
a short, self-contained*, compilable example.

Include with your example a precise description of your expected results and
precisely how the realized results differ.  Literally copy and paste relevant
error messages and other relevant text output.

If circumstances preclude providing an SSCCE, the closer you come to that
ideal the better we're able to comment wisely on your situation.

* Andrew: "self-contained" is a "unit modifier" that precedes the noun
modified, therefore requires a hyphen.  I also discard the term "correct" and
the parentheses because "compilable" subsumes what we're trying to accomplish.
 If the issue is a compiler error, then it's compilable with an expectation
of compiler error; if the issue is run-time, then it's compilable with an
expectation of no compiler error.  IOW, I'm construing "compilable" in the
broadest sense of "ready to submit to the compiler".

Signature

Lew



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.