Verified Answers
A rectangular puzzle exists with all pieces being identically-sized squares. The main part of the
puzzle has a total of 600 pieces and each row of this main part of the puzzle is 30 pieces wide.
Additionally, there is a border of artistic icons completely surrounding this main puzzle area,
and this border is exactly one piece wide, with each piece of the border being the same size as a
main puzzle piece. Finally, at the bottom of the puzzle is one additional row of square pieces
that spells out the title of the puzzle.
The puzzle is composed of all the before-mentioned pieces, each piece being square and the
same size. The PuzzlePiece class is defined as follows:
public class PuzzlePiece
{
private Image image; // Image represented by this piece
private int row; // row where this piece goes
private int col; // col where this piece goes
public PuzzlePiece(Image i, int r, int c)
{
// Implementation not shown
} - ✔✔D
public class Puzzle
{
private PuzzlePiece[][] puzzle = new PuzzlePiece[23][32];
// other instance variables and methods not shown
}
Consider the following code.
,public static void main(String args[])
{
int numArray[][]={{3,5,7},{2,4,6},{9,8,7},{6,5,4}};
if (numArray.length==4)
{
for (int i=0; i<numArray[0].length; i++)
{
System.out.print(numArray[i][2]);
}
}
else
{
for(int i=2; i>-1; i--)
{
System.out.print(numArray[2][i]);
}
}
}
---
What is printed as a result of executing the code?
---
A
,767
B
OutOfBoundsException
C
548
D
987
E
246 - ✔✔A
767
Consider the following code segment.
int[][] heights = new int[3][6];
heights[0][0] = 10;
heights[1][0] = 20;
heights[2][0] = 30;
double total = 0;
int count = 0;
for (int r=0; r < heights.length; r++)
{
for (int c=0; c < heights[r].length; c++)
{
total += heights[r][c]; count++;
}
}
, System.out.println((int) (total/count) + ", " + (int) (total/heights.length) + ", " + (int)
(total/heights[0].length));
---
Which of the following is the output printed to the console after this segment of code is
executed?
---
A
20, 20, 10
B
3, 3, 3
C
20, 20, 20
D
10, 10, 10
E
3, 20, 10 - ✔✔E
3, 20, 10
Consider the following method.
public static void print2DimArray(int[][] nums)
{
for (int i=0; i<nums.length; i++)
{