Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

APCS Printing and objects

Total questions: 10

Worksheet time: 11mins

Name
Class
Date
1.

What is printed by this code?

System.out.println("W");

System.out.println("X");

System.out.print("Y");

System.out.print("Z");

a)

WXYZ

b)

W

XYZ

c)

WX

YZ

d)

W

X

YZ

e)

W

X

Y

Z

2.

What is printed by this code?

System.out.print("cat");

System.out.println("dog");

System.out.println("horse");

System.out.print("cow");

a)

cat dog horse cow

b)

cat doghorsecow

c)

catdoghorse

cow

d)

catdog

horse

cow

e)

cat doghorse cow

3.

Which of the following code segments would print

Hello

a)

System.out.print("Hello");

b)

System.out.print(Hello);

c)

System.out.print(He);

System.out.print(llo);

4.

Which statement correctly declares a variable that can store a temperature rounded to the nearest tenth of a degree?

a)

boolean patientTemp;

b)

double patientTemp;

c)

int patientTemp;

d)

patientTemp = 0;

e)

patientTemp = 0.0;

5.

int a = 1;

int b = 2;

int c = 3;

int d = 4;

double x = a + b * c % d;

What is the value of x when the code segment has been executed?

a)

1.0

b)

2.5

c)

3.0

d)

7.0

e)

9.0

6.

Which of the following arithmetic expressions evaluates to 1 ?

a)

2 / 5 % 3

b)

2 / (5 % 3)

c)

2 / 5 + 1

7.

int x = 10;

int y = 20;

System.out.print(y + x / y);

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

a)

1

b)

1.5

c)

3

d)

20

e)

20.5

8.

A class contains the two methods detailed below:

public void methodA(int arg) – Calls methodB with the value of arg * 10

public void methodB(int arg) – Displays the value of arg + 10

What would be printed as a result of calling methodA(4)?

a)

14

b)

40

c)

50

d)

140

9.

Consider the method

public double secret(int x, String y)

Which of the following lines of code that call this method would compile without error?

a)

int result = secret(4, 4)

b)

int result = secret(4, "4")

c)

double result = secret(4, 4)

d)

double result = secret(4, "4")

e)

double result = secret("4", 4)

10.

Consider the following description of method min.

public int min(int first, int second) – Returns the lesser of its two parameters.

Which of the following lines of code would return the minimum value of p, q, and r

a)

min(min(p, q), r)

b)

min(p, min(q, r))

c)

min(min(p, q), p)