Arrays in Methods Question

+2 Hristijan Ilieski · November 16, 2014
Hello, I would like to ask, in this code, I am passing the values from the kiko array in the change method, and I change the values of the x array in the method. Then I don't return anything from the method, but my kiko array is changed? Why? Can someone explain this a little bit more? Thanks.

public class apples {
public static void main(String args[]){
int kiko[]={3,4,5,6,7};
change(kiko);

for(int y:kiko){
System.out.println(y);
}
}

public static void change(int x[]){
for(int counter=0; counter<x.length; counter++){
x[counter]+=5;
}
}

}

Post a Reply

Replies

Oldest  Newest  Rating
  • 1

Java / Android Development

106,914 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator