Corrections
- the correct answer is II and III
- A method signature consists of the method name and the ordered list of parameter types. Choice I will cause a compiler error if added to the SomeMethods class because it has the same method signature as public void one (int first), since it has the same name (one) and each parameter list consists of a single int parameter. Choice II can be added to the SomeMethods class because, although it has the same name (one), the parameter list has the types String, int which has a different order than the method public void one (int first, String second). Choice III can be added to the SomeMethods class because there are three int parameters and no other method named one has three int parameters.
- the correct answer was “An index of a value that occurs most often in nums”
- The outer loop starts at 0 and loops through all the indices in arr. The inner loop starts at the index that is one more than outer and iterates through all indices to the right of this element. For each iteration of the inner loop, the element at the current value of outer is compared with each subsequent element. If the elements are equal, then count is incremented. This results in counting the number of occurrences of each value in the arr. After the inner loop terminates, if the number of occurrences of the current value is greater than previous highest count, the new count is assigned to m and the index of this element is stored in index. The method then returns the value of index, which represents the index of a value that occurs most often in nums.
- the correct answer is 401
- i forgot basic integer rules for Java, was dividing it like normal numbers
- The first operation that is executed is 404 / 10. Since both 404 and 10 are integers, integer division is used resulting in 40. The value 40 is then multiplied by 10, resulting in 400, and finally 1 is added, meaning 401 is printed.
- the correct answer is “false always”
As a result of De Morgan’s Law, the value of !(x y) is equivalent to !x && !y. The only time x && y is true is when both x and y are true. When x and y are both true, !x && !y is false. Therefore, (x && y) && (!x && !y) will always be false as will (x && y) && !(x y).
- the answer is C
- The outer loop iterates six times for when outer is assigned the values 1 through 6. For each iteration, the number of times the inner loop iterates is dependent on the value of outer. When outer is 1, the inner loop iterates from 1 to 6, incrementing by 1 each time, and prints all even numbers followed by a space (2 4 6). When outer is 2, the inner loop iterates from 2 to 6 and prints all even numbers followed by a space (2 4 6). When outer is 3, the inner loop iterates from 3 to 6 and prints all even numbers followed by a space (4 6). When outer is 4, the inner loop iterates from 4 to 6 and prints all even numbers followed by a space (4 6). When outer is 5, the inner loop iterates from 5 to 6 and prints 6 followed by a space. When outer is 6, the inner loop iterates one time and prints 6 followed by a space.
- the answer is “x”
For the expression to evaluate to true, the expressions on either side of the && operator must be true. If x is true then x y is true regardless of the value of y, meaning (x y) && x evaluates to true. If x is false, the expression evaluates to false regardless of the value of (x y).
- answer:
- The first set of nested for loops sets each element in board to “O”. The next for loop starts val at 0 and increments by 1 until val is 4, when val is 5 the loop terminates. When val is even, board is not updated, so nothing happens when val is 0. When val is 1, row is assigned 1 and col is assigned 0. The boolean condition in the while loop is true, so board[1][0] is assigned “X”. Then col is incremented to 1 and row is decremented to 0 and board[0][1] is assigned “X”. Then col is incremented to 2 and row is decremented to -1 and the while loop terminates. When val is 2, nothing changes about board. When val is 3, row is assigned 3 and col is assigned 0. The boolean condition in the while loop is true, so board[3][0] is assigned “X”. Then col is incremented to 1 and row is decremented to 2 and board[2][1] is assigned “X”. Then col is incremented to 2 and row is decremented to 1 and board[1][2] is assigned “X”. Then col is incremented to 3 and row is decremented to 0 and board[0][3] is assigned “X”. Finally, col is incremented to 4 and row is decremented to -1 and the while loop terminates. When val is 4, nothing changes about board.