APCSA 2nd Semester Study Guide

0.0(0)
studied byStudied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/45

Last updated 2:18 PM on 2/10/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

46 Terms

1
New cards
<p><span>The following class definition does not compile. Which of the following best explains why the class will not compile?</span></p>

The following class definition does not compile. Which of the following best explains why the class will not compile?

The  getInfo  method does not have access to variables named  pName  or  pSpecies.

2
New cards
<p><span>Consider the following class definition. The following statement, which is located in a method in a different class, creates a new Person object with its attribute name initialized to "Washington".</span><br><br><span>Which of the following can be used to replace /* missing constructor */ so that the object p is correctly created?</span></p>

Consider the following class definition. The following statement, which is located in a method in a different class, creates a new Person object with its attribute name initialized to "Washington".

Which of the following can be used to replace /* missing constructor */ so that the object p is correctly created?

public Person(String n) { name = n; }

3
New cards

Which of the following best explains why programmers often include open source code in their programs?

To utilize algorithms that have already been implemented while reducing the risk of raising intellectual property concerns

4
New cards
<p><span><span>Consider the following class declaration. Which of the following methods can be added to the&nbsp;</span><em><span> Pair</span></em><span>&nbsp;class to allow other classes to modify the value of </span><em><span>y</span></em><span>?</span></span></p>

Consider the following class declaration. Which of the following methods can be added to the  Pair class to allow other classes to modify the value of y?

public void setY(int num) { y = num; }

5
New cards
<p><span><span>Consider the following partial class definition. </span></span>Which of the following methods can be added to&nbsp; <span><em><span>SomeClass</span></em></span>&nbsp; to allow other classes to modify the value of&nbsp; <span><em><span>myA</span></em></span>?</p>

Consider the following partial class definition. Which of the following methods can be added to  SomeClass  to allow other classes to modify the value of  myA?

public void setA(int newA) { myA = newA; }

6
New cards
<p><span><span>Which of the following best explains why an error occurs when the classes are compiled?</span></span></p>

Which of the following best explains why an error occurs when the classes are compiled?

The toInches method cannot be accessed from a class other than Measurement.

7
New cards

Which of the following actions is most likely to improve the system reliability of a Java program?

Testing the program with conditions that represent a wide variety of ways the program will be used

8
New cards

A programmer developed a mobile application that is intended for users around the world. The programmer wants to maximize the application’s system reliability. Which of the following actions is most likely to support this goal?

Testing the application under a wide variety of possible conditions

9
New cards
<p><strong>The question refer to the following declarations.</strong><br><strong>…</strong><br><span><span>In a client program which of the following correctly declares and initializes&nbsp;&nbsp;Circle circ&nbsp; with center at (29.5, 33.0) and radius 10.0 ?</span></span></p>

The question refer to the following declarations.

In a client program which of the following correctly declares and initializes  Circle circ  with center at (29.5, 33.0) and radius 10.0 ?

Circle circ = new Circle(new Point (29.5, 33.0), 10.0);

10
New cards
<p><strong>The question refer to the following declarations.</strong><br><strong>…</strong><br><span><span>Which of the following would be the best specification for a Circle method isInside that determines whether a Point lies inside this Circle?</span></span></p>

The question refer to the following declarations.

Which of the following would be the best specification for a Circle method isInside that determines whether a Point lies inside this Circle?

public boolean isInside(Point p)

11
New cards
<p><span><span>Which of the following best explains why an error occurs when the classes are compiled?</span></span></p>

Which of the following best explains why an error occurs when the classes are compiled?

In the  checkPoint  method, the instance variables  num1  and  num2  cannot be accessed from a class other than  Point.

12
New cards
<p><span><span>Which of the following best describes the state of the object </span><em><span>myStudent</span></em><span> as a result of executing this code segment?</span></span></p>

Which of the following best describes the state of the object myStudent as a result of executing this code segment?

myStudent has been initialized such that name contains the string "Bobby" and  age is 0.

13
New cards
<p><span><span>Which of the following statements can be used to replace &nbsp;/* missing code */&nbsp; so that this code segment produces the intended output?</span></span><br><br>This code segment is intended to produce the following output.</p><p class="dap_body">&nbsp;</p><pre><code class="language-Java">(3, -2) 
(4, 0)</code></pre><p></p>

Which of the following statements can be used to replace  /* missing code */  so that this code segment produces the intended output?

This code segment is intended to produce the following output.

 

(3, -2) 
(4, 0)

return "(" + x + ", " + y + ")";

14
New cards

A programmer is developing Java code that can be used to analyze a data file. In which of the following situations would it be best for the programmer to publish the code as open source? 

When the programmer wants to enable other programmers to modify the code for inclusion in their programs

15
New cards
<p><span><span>What is printed as a result of executing this code segment?</span></span></p>

What is printed as a result of executing this code segment?

2.5, 2

16
New cards
<p><span><span>What is printed as a result of executing this code segment if it is executed before any other instances of&nbsp; Shoe&nbsp; are constructed?</span></span></p>

What is printed as a result of executing this code segment if it is executed before any other instances of  Shoe  are constructed?

2

17
New cards
<p><span><span>Consider the following method. Method allEven is intended to return true if all elements in array arr are even numbers; otherwise, it should return false.</span></span><br>…</p><p><span><span>Which of the following replacements for /* </span><em><span>expression / and /</span></em><span> </span><em><span>loop body </span></em><span>*/ should be used so that method allEven will work as intended?</span></span><br><br>A</p><table style="min-width: 50px;"><colgroup><col style="min-width: 25px;"><col style="min-width: 25px;"></colgroup><tbody><tr><td colspan="1" rowspan="1" style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-shadow-colored: 0 0 #0000; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; box-sizing: border-box; border-top: none; border-right: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-left: 1px solid rgb(217, 217, 217); print-color-adjust: exact; text-align: center; padding: 5px; line-height: 1.42857; vertical-align: top; border-image: initial;"><p><span style="line-height: normal;"><u><span>/* </span></u><em><u><span>expression </span></u></em><u><span>*/</span></u></span></p></td><td colspan="1" rowspan="1" style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-shadow-colored: 0 0 #0000; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; box-sizing: border-box; border-top: none; border-right: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-left: 1px solid rgb(217, 217, 217); print-color-adjust: exact; text-align: center; padding: 5px; line-height: 1.42857; vertical-align: top; border-image: initial;"><p><span style="line-height: normal;"><u><span>/* </span></u><em><u><span>loop body </span></u></em><u><span>*/</span></u></span></p></td></tr><tr><td colspan="1" rowspan="1" style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-shadow-colored: 0 0 #0000; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; box-sizing: border-box; border-top: none; border-right: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-left: 1px solid rgb(217, 217, 217); print-color-adjust: exact; text-align: center; padding: 5px; line-height: 1.42857; vertical-align: top; border-image: initial;"><p><span style="line-height: 15.6933px;"><span>false</span></span></p></td><td colspan="1" rowspan="1" style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-shadow-colored: 0 0 #0000; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; box-sizing: border-box; border-top: none; border-right: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-left: 1px solid rgb(217, 217, 217); print-color-adjust: exact; padding: 5px; line-height: 1.42857; vertical-align: top; border-image: initial;"><p><span style="line-height: normal;"><span>if ((arr[k] % 2) == 0)</span></span></p><p><span style="line-height: normal;"><span>&nbsp; isEven = true;</span></span></p><p></p><p></p></td></tr></tbody></table><p>&nbsp;</p><p><strong>B</strong></p><table style="min-width: 50px;"><colgroup><col style="min-width: 25px;"><col style="min-width: 25px;"></colgroup><tbody><tr><td colspan="1" rowspan="1" style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-shadow-colored: 0 0 #0000; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; box-sizing: border-box; border-top: none; border-right: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-left: 1px solid rgb(217, 217, 217); print-color-adjust: exact; text-align: center; padding: 5px; line-height: 1.42857; vertical-align: top; border-image: initial;"><p><span style="line-height: normal;"><u><span>/* </span></u><em><u><span>expression </span></u></em><u><span>*/</span></u></span></p></td><td colspan="1" rowspan="1" style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-shadow-colored: 0 0 #0000; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; box-sizing: border-box; border-top: none; border-right: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-left: 1px solid rgb(217, 217, 217); print-color-adjust: exact; text-align: center; padding: 5px; line-height: 1.42857; vertical-align: top; border-image: initial;"><p><span style="line-height: normal;"><u><span>/* </span></u><em><u><span>loop body </span></u></em><u><span>*/</span></u></span></p></td></tr><tr><td colspan="1" rowspan="1" style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-shadow-colored: 0 0 #0000; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; box-sizing: border-box; border-top: none; border-right: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-left: 1px solid rgb(217, 217, 217); print-color-adjust: exact; text-align: center; padding: 5px; line-height: 1.42857; vertical-align: top; border-image: initial;"><p><span style="line-height: 15.6933px;"><span>false</span></span></p></td><td colspan="1" rowspan="1" style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-shadow-colored: 0 0 #0000; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; box-sizing: border-box; border-top: none; border-right: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-left: 1px solid rgb(217, 217, 217); print-color-adjust: exact; padding: 5px; line-height: 1.42857; vertical-align: top; border-image: initial;"><p></p><p><span style="line-height: normal;"><span>if ((arr[k] % 2) != 0)</span></span></p><p><span style="line-height: normal;"><span>&nbsp; isEven = false;</span></span></p><p><span style="line-height: normal;"><span>else</span></span></p><p><span style="line-height: 15.6933px;"><span>&nbsp; isEven = true;</span></span></p><p></p><p></p><p></p></td></tr></tbody></table><p>&nbsp;</p><p><strong>C</strong></p><table style="min-width: 50px;"><colgroup><col style="min-width: 25px;"><col style="min-width: 25px;"></colgroup><tbody><tr><td colspan="1" rowspan="1" style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-shadow-colored: 0 0 #0000; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; box-sizing: border-box; border-top: none; border-right: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-left: 1px solid rgb(217, 217, 217); print-color-adjust: exact; text-align: center; padding: 5px; line-height: 1.42857; vertical-align: top; border-image: initial;"><p><span style="line-height: normal;"><u><span>/* </span></u><em><u><span>expression </span></u></em><u><span>*/</span></u></span></p></td><td colspan="1" rowspan="1" style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-shadow-colored: 0 0 #0000; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; box-sizing: border-box; border-top: none; border-right: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-left: 1px solid rgb(217, 217, 217); print-color-adjust: exact; text-align: center; padding: 5px; line-height: 1.42857; vertical-align: top; border-image: initial;"><p><span style="line-height: normal;"><u><span>/* </span></u><em><u><span>loop body </span></u></em><u><span>*/</span></u></span></p></td></tr><tr><td colspan="1" rowspan="1" style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-shadow-colored: 0 0 #0000; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; box-sizing: border-box; border-top: none; border-right: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-left: 1px solid rgb(217, 217, 217); print-color-adjust: exact; text-align: center; padding: 5px; line-height: 1.42857; vertical-align: top; border-image: initial;"><p><span style="line-height: 15.6933px;"><span>true</span></span></p></td><td colspan="1" rowspan="1" style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-shadow-colored: 0 0 #0000; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; box-sizing: border-box; border-top: none; border-right: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-left: 1px solid rgb(217, 217, 217); print-color-adjust: exact; padding: 5px; line-height: 1.42857; vertical-align: top; border-image: initial;"><p><span style="line-height: normal;"><span>if ((arr[k] % 2) != 0)</span></span></p><p><span style="line-height: normal;"><span>&nbsp; </span></span><span style="line-height: 15.6933px;"><span>isEven = false;</span></span></p><p></p><p></p></td></tr></tbody></table><p>&nbsp;</p><p><strong>D</strong></p><table style="min-width: 50px;"><colgroup><col style="min-width: 25px;"><col style="min-width: 25px;"></colgroup><tbody><tr><td colspan="1" rowspan="1" style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-shadow-colored: 0 0 #0000; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; box-sizing: border-box; border-top: none; border-right: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-left: 1px solid rgb(217, 217, 217); print-color-adjust: exact; text-align: center; padding: 5px; line-height: 1.42857; vertical-align: top; border-image: initial;"><p><span style="line-height: normal;"><u><span>/* </span></u><em><u><span>expression </span></u></em><u><span>*/</span></u></span></p></td><td colspan="1" rowspan="1" style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-shadow-colored: 0 0 #0000; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; box-sizing: border-box; border-top: none; border-right: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-left: 1px solid rgb(217, 217, 217); print-color-adjust: exact; text-align: center; padding: 5px; line-height: 1.42857; vertical-align: top; border-image: initial;"><p><span style="line-height: normal;"><u><span>/* </span></u><em><u><span>loop body </span></u></em><u><span>*/</span></u></span></p></td></tr><tr><td colspan="1" rowspan="1" style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-shadow-colored: 0 0 #0000; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; box-sizing: border-box; border-top: none; border-right: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-left: 1px solid rgb(217, 217, 217); print-color-adjust: exact; text-align: center; padding: 5px; line-height: 1.42857; vertical-align: top; border-image: initial;"><p><span style="line-height: 15.6933px;"><span>true</span></span></p></td><td colspan="1" rowspan="1" style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-shadow-colored: 0 0 #0000; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; box-sizing: border-box; border-top: none; border-right: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-left: 1px solid rgb(217, 217, 217); print-color-adjust: exact; padding: 5px; line-height: 1.42857; vertical-align: top; border-image: initial;"><p></p><p><span style="line-height: normal;"><span>if ((arr[k] % 2) != 0)</span></span></p><p><span style="line-height: normal;"><span>&nbsp; isEven = false;</span></span></p><p><span style="line-height: normal;"><span>else</span></span></p><p><span style="line-height: 15.6933px;"><span>&nbsp; isEven = true;</span></span></p><p></p><p></p><p></p></td></tr></tbody></table><p><br></p>

Consider the following method. Method allEven is intended to return true if all elements in array arr are even numbers; otherwise, it should return false.

Which of the following replacements for /* expression / and / loop body */ should be used so that method allEven will work as intended?

A

/* expression */

/* loop body */

false

if ((arr[k] % 2) == 0)

  isEven = true;

 

B

/* expression */

/* loop body */

false

if ((arr[k] % 2) != 0)

  isEven = false;

else

  isEven = true;

 

C

/* expression */

/* loop body */

true

if ((arr[k] % 2) != 0)

  isEven = false;

 

D

/* expression */

/* loop body */

true

if ((arr[k] % 2) != 0)

  isEven = false;

else

  isEven = true;


C

/* expression */

/* loop body */

true

if ((arr[k] % 2) != 0)

  isEven = false;

 

18
New cards
<p>Consider the following instance variable and method.<br>…</p><p><span><span>Which of the following is the best postcondition for checkArray ?</span></span></p>

Consider the following instance variable and method.

Which of the following is the best postcondition for checkArray ?

Returns the index of the largest value in array array

19
New cards

Consider the following instance variable and incomplete method. The method is intended to return a string from the array words that would be last alphabetically.

private String[] words;

 

public String findLastWord()

{

/* missing implementation */

}

Assume that words has been initialized with one or more strings containing only lowercase letters. Which of the following code segments can be used to replace /* missing implementation */ so that findLastWord will work as intended?

a.int maxIndex = 0;

for (int k = 0; k < words.length; k++)
{
	if (words[k].compareTo(maxIndex) > 0)
	{

		maxIndex = k;
	}

}

return words[maxIndex];
b.
int maxIndex = 0;

for (int k = 1; k <= words.length; k++)

	{

	if (words[k].compareTo(words[maxIndex]) > 0)
	
	{

		maxIndex = k;

	}

}

return words[maxIndex];
c. 
String maxWord = words[0];

for (int k = 1; k < words.length; k++)

	{

	if (words[k].compareTo(maxWord) > 0)

	{

		maxWord = words[k];

	}

}

return maxWord;

c.

20
New cards
public int[] transform(int[] a)

{

	a[0]++;

	a[2]++;

	return a;

}

The following code segment appears in a method in the same class as transform.

/* missing code */

arr = transform(arr);

After executing the code segment, the array arr should contain {1, 0, 1, 0}. Which of the following can be used to replace /* missing code */ so that the code segment works as intended?

I. int[] arr = {0, 0, 0, 0};

II. int[] arr = new int[0];

III. int[] arr = new int[4];

I and III

21
New cards

A researcher wants to investigate which age group (under 18 years old, or 18 years old and over) is more likely to have downloaded a certain application from an online store. Each customer of the store has a unique ID number. The researcher has the following data sets available.

  • Data set 1 contains an entry for each application available from the store. Each entry includes the name of the application and the total number of customers who have downloaded it.

  • Data set 2 contains an entry for each application available from the store. Each entry includes the ID number and age of the customer who most recently downloaded the application.

  • Data set 3 contains an entry for each customer of the store. Each entry includes the customer’s ID number and the customer’s age.

  • Data set 4 contains an entry for each customer of the store. Each entry includes the customer’s ID number and the names of all the applications downloaded by the customer.

    Which two data sets can be combined and analyzed to determine the desired information?

Data sets 3 and 4

22
New cards
<p>Which of the following best describes the behavior of code segment I and code segment II&nbsp;?</p>

Which of the following best describes the behavior of code segment I and code segment II ?

Code segment I will cause an ArrayIndexOutOfBoundsException and code segment II will print 45678.

23
New cards
<p><span><span>What are the contents of arr after executing this code segment?</span></span></p>

What are the contents of arr after executing this code segment?

{10, 21, 30, 41, 50, 61}

24
New cards

Consider the following method.

public void changeIt(int[] arr, int index, int newValue)

{

	arr[index] += newValue;

}

Which of the following code segments, if located in a method in the same class as changeIt, will cause the array myArray to contain {0, 5, 0, 0} ?

A.
int[] myArray = new int[4];

changeIt(myArray, 1, 5);
B.
int[] myArray = new int[4];

changeIt(myArray, 2, 5);
C.
int[] myArray = new int[5];

changeIt(myArray, 1, 4);
D.
int[] myArray = new int[5];

changeIt(myArray, 1, 5);

A
int[] myArray = new int[4];

changeIt(myArray, 1, 5);

25
New cards
term image

(pos < arr.length) && (arr[pos] != val)

26
New cards
<p><span><span>Consider the following instance variable nums and method findLongest with line numbers added for reference. Method findLongest is intended to find the longest consecutive block of the value target occurring in the array nums; however, findLongest does not work as intended.</span></span><br><br><span><span>For example, if the array nums contains the values [7, 10, 10, 15, 15, 15, 15, 10,10, 10, 15, 10, 10], the call findLongest (10) should return 3, the length of the longest consecutive block of 10s.</span></span><br><br><span><span>Which of the following changes should be made so that method findLongest will work as intended?</span></span></p>

Consider the following instance variable nums and method findLongest with line numbers added for reference. Method findLongest is intended to find the longest consecutive block of the value target occurring in the array nums; however, findLongest does not work as intended.

For example, if the array nums contains the values [7, 10, 10, 15, 15, 15, 15, 10,10, 10, 15, 10, 10], the call findLongest (10) should return 3, the length of the longest consecutive block of 10s.

Which of the following changes should be made so that method findLongest will work as intended?

Insert the statement lenCount = 0; between lines 12 and 13.

27
New cards
<p><span><span>The method countTarget below is intended to return the number of times the value target appears in the array arr. The method may not work as intended.</span></span><br><br><span><span>Which of the following changes, if any, can be made to line 4 so that the method will work as intended?</span></span></p>

The method countTarget below is intended to return the number of times the value target appears in the array arr. The method may not work as intended.

Which of the following changes, if any, can be made to line 4 so that the method will work as intended?


Changing j <= arr.length; to j < arr.length;

28
New cards
<p>What is printed as a result of executing the code segment?</p>

What is printed as a result of executing the code segment?

fox and groundhog

29
New cards
<p><span><span>Consider the following method that is intended to modify its parameter nameList by replacing all occurrences of name with newValue.</span></span></p><p></p><p><span><span>Which of the following can be used to replace /* </span><em><span>expression </span></em><span>*/ so that replace will work&nbsp;as intended?</span></span></p>

Consider the following method that is intended to modify its parameter nameList by replacing all occurrences of name with newValue.

Which of the following can be used to replace /* expression */ so that replace will work as intended?

nameList.get(j).equals(name)

30
New cards
31
New cards
<p><span><span>In the following code segment, &nbsp;words &nbsp;is an &nbsp;ArrayList &nbsp;of two or more&nbsp; String&nbsp; objects.</span></span><br><span><span>…</span></span><br><span><span>Which of the following best describes the value assigned to&nbsp; count&nbsp; as a result of executing the code segment?</span></span></p>

In the following code segment,  words  is an  ArrayList  of two or more  String  objects.

Which of the following best describes the value assigned to  count  as a result of executing the code segment?

The number of elements in  words  whose length is the same length as the element immediately preceding it

32
New cards

The following code segment initializes and processes an  ArrayList  of  String  elements. The loop is intended to delete every other element in the  ArrayList  starting with the first element.

ArrayList<String> nameList = new ArrayList<String>();
nameList.add("Stacey");
nameList.add("Bob");
nameList.add("Susan");
nameList.add("Pete");

for (int i = 0; i < nameList.size(); i++)
{
   /* missing code */
}

After the code segment is executed,  nameList  should contain  ["Bob", "Pete"].

Which of the following can replace /* missing code */ so that the code segment works as intended?

nameList.remove(i);

33
New cards
<p><span><span>In the following code segment, assume that the ArrayList numList has been properly declared and initialized to contain the Integer values [1, 2, 2, 3]. The code segment is intended to insert the Integer value val in numList so that numList will remain in ascending order. The code segment does not work as intended in all cases.</span></span><br><br><span><span>For which of the following values of val will the code segment not work as intended?</span></span></p>

In the following code segment, assume that the ArrayList numList has been properly declared and initialized to contain the Integer values [1, 2, 2, 3]. The code segment is intended to insert the Integer value val in numList so that numList will remain in ascending order. The code segment does not work as intended in all cases.

For which of the following values of val will the code segment not work as intended?

4

34
New cards
<p><span><span>Consider the following data field and method. The method removeDups is intended to remove all adjacent duplicate numbers from myData, but does not work as intended.</span></span></p><p></p><p><span>For example, if myData has the values 3 3 4 4 4 8 7 7 7, after calling removeDups, myData should have the values 3 4 8 7.</span><br><br>Which of the following best describes how to fix the error so that<span> removeDups </span>works as intended?</p>

Consider the following data field and method. The method removeDups is intended to remove all adjacent duplicate numbers from myData, but does not work as intended.

For example, if myData has the values 3 3 4 4 4 8 7 7 7, after calling removeDups, myData should have the values 3 4 8 7.

Which of the following best describes how to fix the error so that removeDups works as intended?

There should be an else before the statement k++;

35
New cards

Consider the following data field and method. The method removeDups is intended to remove all adjacent duplicate numbers from myData, but does not work as intended.

For example, if myData has the values 3 3 4 4 4 8 7 7 7, after calling removeDups, myData should have the values 3 4 8 7.

Assume that myData has the following values.

2 7 5 5 5 5 6 6 3 3 3

Which of the following represents myData after the incorrect removeDups is executed?


2 7 5 5 6 3 3

36
New cards

In the following code segment,  intList  is properly declared and initialized as an  ArrayList<Integer>  variable.

 int someVal = 0;

for (int i = 0; i < intList.size(); i += 2) 
{
   someVal++;
}

System.out.println(someVal);

Which of the following best describes the value printed as a result of executing the code segment?

The number of elements in even-numbered indexes in intList

37
New cards

Consider the following code segment

ArrayList<String> oldList = new ArrayList<String>();
oldList.add("a");
oldList.add("b");
oldList.add("c");

ArrayList<String> newList = new ArrayList<String>();

/* missing code */

After executing this code segment,  newList  should contain  ["c", "b", "a", "a", "b", "c"].

Which of the following can replace  /* missing code */  to produce this result?

A
for (String s : oldList)
{
   newList.add(s);
   newList.add(s);
}
B
for (String s : oldList)
{
   newList.add(s);
   newList.add(0, s); 
}
C
for (int j = 0; j < oldList.size(); j++)
{
   newList.add(oldList.get(0));
   newList.add(oldList.get(j)); 
}
D
for (int j = 0; j < oldList.size(); j++)
{
   newList.add(j, oldList.get(j));
   newList.add(0, oldList.get(j)); 
}

B
for (String s : oldList)
{
   newList.add(s);
   newList.add(0, s); 
}

38
New cards
ArrayList<Integer> nums = new ArrayList<Integer>();

nums.add(3);
nums.add(2);
nums.add(1);
nums.add(0);
nums.add(0, 4);
nums.set(3, 2);
nums.remove(3);
nums.add(2, 0);

Which of the following represents the contents of nums after the code segment is executed?

[4, 3, 0, 2, 0]

39
New cards
<p><span><span>Which of the following can replace&nbsp; /* missing code */&nbsp; so the method works as intended?</span></span></p>

Which of the following can replace  /* missing code */  so the method works as intended?

if (b.getPages() > maxPages)
{
   maxPages = b.getPages();
}

40
New cards
public static boolean mystery(ArrayList<Integer> numbers)
{
   int prev = Integer.MAX_VALUE;
   for (int num : numbers)
   {
      if (num > prev)
      {
         return false;
      }
      prev = num;
   }
   return true;
}

Which of the following best describes the behavior of the method?

It returns  true  if  numbers  is sorted from greatest to least and returns  false  otherwise.

41
New cards
<p>What are the contents of&nbsp; <code>numbers</code>&nbsp; after executing the code segment?</p>

What are the contents of  numbers  after executing the code segment?

[15, 15, 4, 4, 19, 19, 7, 7]

42
New cards
public static void processNumbers(ArrayList<Integer> numbers)
{
   int last = numbers.size() - 1;
   numbers.add(0, numbers.get(last));
   numbers.remove(last + 1);
}

Which of the following best describes the preconditions necessary for the method to run without error?

The  ArrayList  must contain at least one element.

43
New cards

In the code segment shown, myList is an ArrayList of integers. The code segment is intended to remove all elements with the value 0 from myList.

int j = 0;
while (j < myList.size())
{
   if (myList.get(j) == 0)
   {
      myList.remove(j);
   }
   j++;
}

The code segment does not always work as intended. 

For which of the following lists does the code segment not produce the correct result?

[1, 0, 0, 2]

44
New cards

Consider the following data field and method.

private int[][] mat;

public int mystery(int r, int c)

{

  if (r != 0 || c != 0)

  {

    return (mat[r][c] + mystery(r - 1, c - 1));

  }

  else

  {

    return mat[r][c];

  }

}

Assume that mat is the 2-D array shown below.

 

0

1

2

3

0

0

1

2

3

1

4

5

6

7

2

8

9

10

11

3

12

13

14

15

 

What value is returned as a result of the call mystery(2, 3)?

No value is returned because mystery throws an ArrayIndexOutOfBoundsException.

45
New cards
int[][] board = new int[5][4]; 

/* code to initialize board */

int total = 0; 
for (int r = 1; r < board.length; r += 2) 
{ 
   for (int c = 0; c < board[0].length; c++) 
   { 
      total += board[r][c]; 
   } 
}

Which of the following best describes the value of  total  as a result of executing the code segment?

It contains the sum of elements in odd-numbered rows.

46
New cards
public static boolean checkIndices(double[][] data,
                                   int row, int col) 
{ 
   int numRows = data.length; 
    
   if (row < numRows) 
   { 
      int numCols = data[0].length; 
      return col < numCols; 
   } 
   else 
   { 
      return false; 
   } 
}

Consider the following statement, which appears in a method in the same class as  checkIndices.

 

double[][] table = new double[5][6]; 

Which of the following method calls will return the value  true?

checkIndices(table, 4, 5)

Explore top notes

note
Unit 7: Short Fiction III
Updated 851d ago
0.0(0)
note
economics
Updated 397d ago
0.0(0)
note
3. Cohen et al. 2021
Updated 1110d ago
0.0(0)
note
APUSH Unit 6
Updated 394d ago
0.0(0)
note
The Italian Renaissance.
Updated 221d ago
0.0(0)
note
AP Human Geography - Unit 2
Updated 493d ago
0.0(0)
note
Unit 7: Short Fiction III
Updated 851d ago
0.0(0)
note
economics
Updated 397d ago
0.0(0)
note
3. Cohen et al. 2021
Updated 1110d ago
0.0(0)
note
APUSH Unit 6
Updated 394d ago
0.0(0)
note
The Italian Renaissance.
Updated 221d ago
0.0(0)
note
AP Human Geography - Unit 2
Updated 493d ago
0.0(0)

Explore top flashcards

flashcards
AMG Final Exam Study Guide
150
Updated 1015d ago
0.0(0)
flashcards
Capitulum 24 (Non verb)
23
Updated 381d ago
0.0(0)
flashcards
Module 1
58
Updated 973d ago
0.0(0)
flashcards
Aeronautical Laboratory Prelim
113
Updated 1039d ago
0.0(0)
flashcards
Don Quijote Vocabulario
64
Updated 1172d ago
0.0(0)
flashcards
AMG Final Exam Study Guide
150
Updated 1015d ago
0.0(0)
flashcards
Capitulum 24 (Non verb)
23
Updated 381d ago
0.0(0)
flashcards
Module 1
58
Updated 973d ago
0.0(0)
flashcards
Aeronautical Laboratory Prelim
113
Updated 1039d ago
0.0(0)
flashcards
Don Quijote Vocabulario
64
Updated 1172d ago
0.0(0)