Search Header Logo

Chapter 2 Review

Authored by Samuel Keener

11th - 12th Grade

Used 66+ times

Chapter 2 Review
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

11 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

The code segment below is intended to calculate the circumference c of a circle with the diameter d of 1.5. The circumference of a circle is equal to its diameter times pi.


/* missing declarations */

c = pi * d;


Which of the following variable declarations are most appropriate to replace /* missing declarations */ in this code segment?

int pi = 3.14159;

int d = 1.5;

final int c;

final int pi = 3.14159;

int d = 1.5;

int c;

final double pi = 3.14159;

double d = 1.5;

double c;

double pi = 3.14159;

double d = 1.5;

final double c = 0.0;

final double pi = 3.14159;

final double d = 1.5;

final double c = 0.0;

2.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Consider the following code segment.


int x = 5;

int y = 6;

/* missing code */

z = (x + y) / 2;


Which of the following can be used to replace /* missing code */ so that the code segment will compile?


I. int z = 0;

II. int z;

III. boolean z = false;

I ONLY

II ONLY

I AND II ONLY

II AND III ONLY

I, II, AND III

3.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Consider the following code segment.

int a = 5;

int b = 8;

int c = 3;

System.out.println(a + b / c * 2);

What is printed as a result of executing this code?

2

6

8

9

14

4.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

The following code segment is intended to interchange the values of the int variables x and y. Assume that x and y have been properly declared and initialized.


int temp = x;

/* missing code */


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

x = y;

x = temp;

x = y;

y = temp;

y = x;

x = temp;

y = x;

temp = y;

y = x;

temp = x;

5.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Consider the following code segment, which is intended to print the digits of the two-digit int number num in reverse order. For example, if num has the value 75, the code segment should print 57. Assume that num has been properly declared and initialized.


/* missing code */

System.out.print(onesDigit);

System.out.print(tensDigit);


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

int onesDigit = num % 10;

int tensDigit = num / 10;

int onesDigit = num / 10;

int tensDigit = num % 10;

int onesDigit = 10 / num;

int tensDigit = 10 % num;

int onesDigit = num % 100;

int tensDigit = num / 100;

int onesDigit = num / 100;

int tensDigit = num % 100;

6.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Which of the following expressions evaluate to 7 ?

I.9 + 10 % 12

II. (9 + 10) % 12

III. 9 – 2 % 12

I ONLY

II ONLY

I AND III

II AND III

I, II, AND III

7.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Consider the following code segment.


int a = 5;

int b = 4;

int c = 2;

a *= 3;

b += a;

b /= c;

System.out.print(b);


What is printed when the code segment is executed?

2

4

9

9.5

19

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?