I'm having difficulty solving the table test of the following code, could someone show me the output and how do I do it?
public class Principal
{
public static void main(String args[]) {
int array[] = {1, 2, 3, 4, 5};
int aux[] = array;
for(int counter = 0; counter < aux.length; counter++) {
aux[counter]++;
}
for(int counter=0; counter < array.length; counter++) {
System.out.println(++array[counter]);
}
}
}
What I understand: I have an array (vector) with 5 numbers with positions 0 through 4.
I have a aux
variable that is the same size as the array (vector).
I understood that array.length
is to get the size of the vector, that is to say the maximum size of my vector, which in this case is 5
.
I did not understand: aux[counter]++
within first for . What is your true purpose?
I'm still a little hesitant when it comes to doing the table test , because when you ask for counter++
, I never really know the value I put on the bench test.
Does this counter++
add the value of my counter variable or do I have to skip so many houses of the variable? Ex:
counter = 0;
counter++;
counter = 1;
Dai leap 1 home and print on the screen the value that is in the memory space 1 of the counter, is not it? But when counter
becomes 2? Do I count from 1 in memory space or from 0?