I am currently reading Downey's Think Java which recently introduced the enhanced for loop. It was mentioned that the enhanced for loop doesn't take element indices into consideration when it's traversing the array. I thought that this wouldn't inhibit something like the following method from working:
public static double[] powArray(double[] a) {
for (double value : a) {
value = Math.pow(value, 2.0);
}
return a;
}
However, it seems that it does (the rest of the code to which this belongs seems fine). Just to note, this method ends up returning the same array when I run the following:
System.out.println(Arrays.toString(powArray(a)));
I suppose I'm having trouble understanding whether the issue here lies in how I'm handling the enhanced for loop or array references. Thanks in advance!