#How to fix this basic problem

6 messages · Page 1 of 1 (latest)

bright ledge
#

this can be an alternative but i am interested in doing them in methods form

stark nexus
#

You might have heard that Java is pass-by-value. You can't reassign a variable you passed as parameter, or more exactly doing so has no effect on what was passed.

#

Mostly because when you define a method with a parameter:

public static void twice(int a) {
  a = a + a;
  return a;
}

then what do you think happens to 3 when you call twice(3) ?

#

In theory you could pass as parameter an array of three ints. As arrays are objects, they're always pointed to, so the array is not copied, only the reference to it is copied.
You can put new values inside the array, you just can't reassign the array itself.

bright ledge
stark nexus
#

what will what? You're responding to a specific line of mine but that looks out of context