vendredi 10 avril 2015

My nested for loop is not changing the array

Im not sure why my nested for loop is not going through the if statements more then once. After the initial run through, I am trying to make the copy of the new array become the one that goes through the if statements and draws on a new line. Area is being subtracted each time, however nothing is being drawn which means the if statements are not being run. Not sure why not.



public static int [] completion(int [] updated, int length, double width)
{
int [] second = new int [length];
double ending = 49;
double endingY = 20;
double x = 1;
double y = 20;
double begin = 2;
double area = 20;
for(int k = 0; k < 20; k++){
for(int i = 1; i < 49 - 1; i++) {
int [] done = updated;
if(0 == done[i - 1] && 0 == done[i] && 0 == done[i + 1]){
StdDraw.square(begin,area,width);
begin = begin + 1;
second[i] = 0;
}
else if (1 == done[i - 1] && 1 == done[i] && +
1 == done[i + 1]){
StdDraw.square(begin,area,width);
begin = begin + 1;
second[i] = 0;
}
else {
StdDraw.filledSquare(begin, area, width);
begin = begin + 1;
second[i] = 1;
}

}
updated = second.clone();
area = area - 1;
StdDraw.square(x,y,width);
StdDraw.square(ending,endingY,width);
y = y-1;
updated[0] = 0;
updated[48] =0;
endingY = endingY - 1;





}
return updated;
}

Aucun commentaire:

Enregistrer un commentaire