Re: how to call a function
dan wrote:
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, [sic] 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() ?
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".
--
Lew