CSE 8A Lecture Notes - Lecture 7: Foreach Loop
Document Summary
Lecture 7 (cid:894)(cid:1005)(cid:1004)/(cid:1004)7(cid:895) more effect on picture. Pixel[] pixelarray = this. getpixels(): this is how you declare an array to hold elements of type pixel, the elements inside the array are going to be the individual pixels inside the code that calls this method. For loops differ from for-each loops: for loops are more powerful. Goes through everything: for-each loops will hit everything in the array. When casting from a decimal to an int -> java rounds down. getwidth() -> (cid:272)o(cid:374)verts it (cid:271)a(cid:272)k to (cid:862)hu(cid:373)a(cid:374)(cid:863) (cid:272)ou(cid:374)ti(cid:374)g: other methods like . getwidth() do the same thing -> get (cid:862)hu(cid:373)a(cid:374)(cid:863) (cid:272)ou(cid:374)ti(cid:374)g. Debug by printing out variables into console. How do you know which data type a variable is, and if it is a reference? int value = 0; Pixel[] pixarray = this. getpixels(); int index = 0; In the code above, there are four references value, pixarray, index, and p1. These are variables that have not been initialized, but have been declared.