Class HeapQuiz {
int id = 0;
public static void main(
String[] args) {
int x - 0;
HeapQuiz [] hq = new HeapQuiz[5];
while ( x < 3) {
hq[x] = new HeapQuiz();
hq[x].id = x;
x = x + 1;
}
hq[3] = hq[1];
hq[4] = hq[1];
hq[3] = null;
hq[4] = hq[0];
hq[0] = hq[3];
hq[3] = hq[2];
hq[2] = hq[0];
//do stuff
}
}
Ok this is what I understand so far.
while x < 3 the program will run.
hq[x] = new HeapQuiz (); this means it will take on the value of HeapQuiz
hq[x].id = x; this means id = the value of x
x = x + 1; in the beggening x = 0 in this case x is now 1...
This is where I stop understanding and start guessing
My guess:
since in the beggining x = 0 does that mean hq[4] = h[0] and hq[2] = hq[0]; ? if so as long
as the program runs I'm assuming when x = 1 hq[3] = [hq1] and hq[4] = hq[1]?
when x = 2, the answer is hq[3] = hq[2]
I dont want to compile the program I just want to learn how to read
java, compiling is sort of cheating when your trying to learn...