AP CS A Test #2

AP CS A Test #2

9th - 12th Grade

12 Qs

quiz-placeholder

Similar activities

"switch" Java Statement - 1

"switch" Java Statement - 1

9th - 10th Grade

17 Qs

Arithmetic Types Declare Initialize Relation Logical Ops

Arithmetic Types Declare Initialize Relation Logical Ops

9th Grade - University

16 Qs

Java Arrays Basic

Java Arrays Basic

10th - 12th Grade

15 Qs

Arrays

Arrays

9th - 12th Grade

16 Qs

Arrays Unit

Arrays Unit

10th - 12th Grade

15 Qs

Array

Array

10th - 12th Grade

15 Qs

One Dimensional Array

One Dimensional Array

9th Grade - University

14 Qs

Java 1D Arrays

Java 1D Arrays

9th Grade - University

14 Qs

AP CS A Test #2

AP CS A Test #2

Assessment

Quiz

Computers

9th - 12th Grade

Hard

Used 1+ times

FREE Resource

12 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

Consider the following code segment:

int x = 3;

double y = Math.pow(x, 3);

double z = Math.sqrt(y - Math.abs(-2));

What is the value of z after this code segment has executed?

0.0

3.0

5.0

9.0

10.0

2.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

What does the expression "Nomnomnom yummy turkey".indexOf("Thank") evaluate to?

Thank

Nomnomnom

turkey

-1

0

3.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

Consider the following code segment.

int x = /* some integer value */ ;

int y = /* some integer value */ ;

boolean result = (x < y);

result = ( (x >= y) && !result );

Which of the following best describes the conditions under which the value of result will be true after the code segment is executed?

Only when x < y

Only when x >= y

Only when x and y are equal

The value will always be true .

The value will always be false .

4.

MULTIPLE CHOICE QUESTION

5 mins • 1 pt

Consider the following instance variables and incomplete method that are part of a class that represents an item. The variables years and months are used to represent the age of the item, and the value for months is always between 0 and 11, inclusive. Method updateAge is used to update these variables based on the parameter extraMonths that represents the number of months to be added to the age.

private int years;

private int months; // 0 <= months <= 11

public void updateAge(int extraMonths)

{

/* body of updateAge */

}

Which of the following code segments shown below could be used to replace /* body of updateAge */ so that the method will work as intended?

I int yrs = extraMonths % 12;

int mos = extraMonths / 12;

years = years + yrs;

months = months + mos;

II int totalMonths = years * 12 + months + extraMonths;

years = totalMonths / 12;

months = totalMonths % 12;

III int totalMonths = months + extraMonths;

years = years + totalMonths / 12;

months = totalMonths % 12;

I only

II only

III only

I and II only

II and III

5.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

Consider the following method.

public static void conditionalTest(int a, int b)

{

if ((a > 0) && (b > 0))

{

if (a > b)

System.out.println("A");

else

System.out.println("B");

}

else if ((b < 0) || (a < 0))

System.out.println("C");

else

System.out.println("D");

}

What is printed as a result of the call conditionalTest(3, -2) ?

A

B

C

D

Nothing is printed

6.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

Consider the following static method.

public static int calculate(int x)

{

x = x + x;

x = x + x;

x = x + x;

return x;

}

Which of the following can be used to replace the body of calculate so that the modified version of calculate will return the same result as the original version for all possible values of x ?

return 3 + x;

return 3 * x;

return 4 * x;

return 6 * x;

return 8 * x;

7.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

Assume that a and b are boolean variables and have been properly initialized.

(a && b) || !(a && b)

The result of evaluating the expression above is best described as:

Always true

Always false

true only when a is true and b is true

true only when a and b have the same value

true only when a and b have different values

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?