Pixel pixelArray thisgetPixels intvalue 0 intindex 0 while
Pixel[] pixelArray= this.getPixels();
intvalue = 0;
intindex = 0;
while (index < pixelArray.length/4)
{
value = pixelArray[index].getRed();
value = (int) (value * 0.5);
pixelArray[index].setRed(value);
index = index + 1;
}
the answer is B! could explain why B is answer? :)
and what is that meaning of \"index < pixelArray.length\" ?
Thanks!
A D None RID B CDSolution
Please follow the code and comments for description :
CODE :
// get the array of pixel for this picture object
Pixel[] pixelArray = this.getpixelArray();
int value = 0; // the amount of red
int index = 0; // start the intindex at 0
// loop while the index is less than the quarter length of the pixel Array
while (index < pixelArray.length/4) {
// get the current pixel at this index and get the red value at the pixel
value = pixelArray[index].getRed();
// set the red value to half what it was
value = (int) (value * 0.5);
// set the red for this pixel to the new value
pixelArray[index].setRed(value);
// increment the intindex
index = index + 1;
}
So the answer is OPTION B.
index < pixelArray.length : This is used to loop while the index is less than the length of the pixels array.
Hope this is helpful.