Can someone please explain what is going on in this method?
class test{
public static void main(String args[])
{
int[] x = new int[4];
int[] xy = new i
int[] x = new int[4];
This creates an array of 4 elements. Each element's value is 0.
for(int j : x) {
xy[j] += 1;
}
This iterates through all the values of x
. At each iteration, j
is the next element in x
, but since all elements are initialized to 0, j is always 0. So, the 4 iterations increment xy[0]
.