Page 1171 - AP Computer Science A, 7th edition
P. 1171

5. (A) The first line in choice A returns a random integer that lies bet w een 0 and allResponses.length–1. T his range corresponds to the range of the array indexes so it is correct. Choice B is garbage—you cannot cast a real number to a string. Choice C fails because Math.random() is type double and you require an int; you must do the cast to int shown in choice A. Choice D fails because the element allResponses[allResponses.length–1] w ill nev er be returned: i will contain a random int from 0 to allResponses.length–2. C hoic e E ret urns an int, not a String.


































































































   1169   1170   1171   1172   1173