Copy the code below and run it to see what happens
/**
* ArrayParameters objects vs primitives.
* @author (oc)
*/
public class ArrayParameters
{
// instance variables - replace the example below with your own
private int x=3;
private int[] xx={5,10,17,22,8};
/**
* Constructor for objects of class ArrayParameters
*/
public ArrayParameters()
{
System.out.print("initially x="+x+" and xx=");printArray(xx);
System.out.println();
int y = doublex(x);
int[] yy = doublexx(xx);
System.out.println("x="+x+", y="+y);
System.out.print("xx=");printArray(xx);
System.out.print("yy=");printArray(yy);
}
/**
* An example of a method - replace this comment with your own
*
* @param y a sample parameter for a method
* @return the sum of x and y
*/
public int doublex(int y)
{
y = y*2;
return y;
}
public int[] doublexx(int[] y)
{
for(int i=0;i<y.length;i++)y[i]=y[i]*2;
return y;
}
public void printArray(int[] a){
System.out.print("{");
for(int i=0;i<a.length;i++)System.out.print(a[i]+", ");
System.out.println("}");
}
}