Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Function Call Problem

 
John Stevens
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have various function calls in a program:
//FUNCTION CALLS
enterDiagonal(matrix, sizeIn);
enterBelowDiagonal(matrix);
enterAboveDiagonal(matrix);
PrintTri(matrix, sizeIn);
int [] oneD = storeTo1D(matrix, sizeIn);
int [] Vectwo = setUpVector2(sizeIn);
int [] sumarr = AddOrSub(sizeIn, oneD, Vectwo);
storeTo1D(matrix, sizeIn);
setUpVector2(sizeIn);
AddOrSub(sizeIn, oneD, Vectwo);
displayarray(oneD, Vectwo, sumarr);
The int[] declaration in the middle indicate the use of local function variables in other functions.
The problem I am having is one the function 'AddOrSub(sizeIn, oneD, Vectwo);' is finished, it seems to go all the way back to 'storeTo1D(matrix, sizeIn);'.
I don't understand why its doing this but Iam pretty sure its those int[] reference declarations that are causing this. I've tried switching them around bu no luck.
Can anyone point me in the right direction?
Thanks.
 
Joe Ess
Bartender
Posts: 9311
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by John Stevens:

The int[] declaration in the middle indicate the use of local function variables in other functions.

No it doesn't. It receives the return value of the method call. Very Different Things. I refer you back to the scope article I linked in you previous question.


The problem I am having is one the function 'AddOrSub(sizeIn, oneD, Vectwo);' is finished, it seems to go all the way back to 'storeTo1D(matrix, sizeIn);'.
Thanks.

I don't quite understand this statement, but I think you believe you have declared a link to local variables in other functions by declaring variables with similar names in your main method. Not the case.
I can't figure out why you are calling these methods twice, once using the return values, once not.

What you are doing is calling AddOrSub twice on the same instances of oneD and Vectwo. The second calls to store and setUp don't change those values in this method. Study the scope document. That's what your problem is.
 
Joe Ess
Bartender
Posts: 9311
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm. Can't edit. Here's your previous submission
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic