How to pass an Array Attention Eric Sosman  
Author Message
klynn47





PostPosted: 2005-1-21 8:51:00 Top

java-programmer, How to pass an Array Attention Eric Sosman One problem that I see is with the following.

for(int i = 0; i<len; i++)
{ a[i] = rand.nextInt(); // fill array with random num

System.out.println("a[" + i + "] = " + a[i]);}
return a;
}

The elements of an int array are initialized to 0. Because you have the
System.out.println and return statement within the body of the for
loop, the 1st element of the array will be set to a random int, and
then the array will be returned. When a return statement is executed,
the method exits at that point and nothing else in the method is
executed.