I have been presented with a method, that I dont understand how works. The if-statement says that x should be bigger than 2, but with the ++x, x is only one. Same goes for y. When I try printing it to the terminal it prints "6 3". I cant seem to figure out why the method executes the if-statement when both the x and they y is only 1, smaller than 2.
public int metode() {
int x = 0;
int y = 0;
for(int z = 0; z<5; z++){
if((++x > 2) && (++y > 2)){
x++;
}
}
System.out.println(x + " " + y);
return 0;
}
Can anyone explain how this works?
Aucun commentaire:
Enregistrer un commentaire