Sorry for my some stupid question but I've learned that parameters in Java passed by value. If I write code like this, i get 69, not 690 because in this method I changed the copy of variable num.
public class Main
{
public static void main(String[] args)
{
int num = 69;
mystery(num);
System.out.println(num); //69
}
public static void mystery(int num)
{
num *= 10;
}
}
But in this example values of my array are changed!!! And I don't understand why, cause I thought parameters passed by value!!
public class Main
{
public static void main(String[] args)
{
int[] a = {1,2,3,4,5};
mystery2(a);
for(int e : a)
{
System.out.print(e + " "); // 10 20 30 40 50
}
}
public static void mystery2(int[] array)
{
for(int i = 0; i < array.length; i++)
{
array[i] *= 10;
}
}
}