66 Question Time Trial Reflection
Afterthoughts
I thought that trying to do it in an hour and a half was the biggest constraint of the assignment. For the questions that were harder, or that I was spending too much time on, I took my best educated guess and moved on. I am happy college board provides explainations for the wrong and write answers after they give the score back.
- I forgot to change the operand of or to and but the rest of the logical operators were correct
- two-dimensional arrays are stored as arrays of one-dimensional arrays. Line 8 is intended to assign to row, a one-dimensional array of int values, a single row of the two-dimensional array arr. The original version of line 8 attempts to assign a row of col, but col is not a two-dimensional array.
- Correct. Since the original expression prints "dog" when a < b || c != d evaluates to true, an equivalent code segment would print "cat" when the negative of the expression, or !(a < b || c != d), evaluates to true. Applying De Morgan’s laws produces the equivalent Boolean expression a >= b && c == d for the case when "cat" should be printed.
- you needed to insert the statement lenCount = 0; between lines 12 and 13. But i said for it to be between 10 and 11
- The original code segment uses an enhanced for loop to iterate through the elements of array arr, uses variable sum to accumulate the sum of twice the value of the elements in the array, and prints the value of sum. This code segment produces the same output using a regular for loop. As the index k varies from 0 to arr.length - 1, twice the value of arr[k] accumulates in the variable sum.
- The original code segment prints "YES" for odd integers and "NO" for even integers. Code segment I produces the same output as the original code segment because the result of evaluating the expression x % 2 has only two possible values: 0 if x is even and 1 if x is odd. Code segment II produces the same output as the original code segment because the second else clause that prints "NONE" is never reached. Code segment III does not produce the same output as the original code segment. It creates a local boolean variable and assigns it the result of x % 2 == 0, but when using it in the if statement, the wrong branch is taken so that "YES" is printed for even integers and "NO" is printed for odd integers.
- a==b because if it was neither less than or greater than one another it means that they have to be equal
- The given code segment prints the array elements in order from left to right using an enhanced for loop. Code segment I uses elements as indices. The first element of arr is 1, and arr[1] is 2; the second element is 2, and arr[2] is 4; the third element is 4, and arr[4] is 3; etc. Code segment II prints the indices 0 to 4 in order. Code segment III prints the array elements in order from left to right using a for loop.