WorksheetsAPCS Printing and objects
Total questions: 10
Worksheet time: 11mins
What is printed by this code?
System.out.println("W");
System.out.println("X");
System.out.print("Y");
System.out.print("Z");
WXYZ
W
XYZ
WX
YZ
W
X
YZ
W
X
Y
Z
What is printed by this code?
System.out.print("cat");
System.out.println("dog");
System.out.println("horse");
System.out.print("cow");
cat dog horse cow
cat doghorsecow
catdoghorse
cow
catdog
horse
cow
cat doghorse cow
Which of the following code segments would print
Hello
System.out.print("Hello");
System.out.print(Hello);
System.out.print(He);
System.out.print(llo);
Which statement correctly declares a variable that can store a temperature rounded to the nearest tenth of a degree?
boolean patientTemp;
double patientTemp;
int patientTemp;
patientTemp = 0;
patientTemp = 0.0;
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?
1.0
2.5
3.0
7.0
9.0
Which of the following arithmetic expressions evaluates to 1 ?
2 / 5 % 3
2 / (5 % 3)
2 / 5 + 1
int x = 10;
int y = 20;
System.out.print(y + x / y);
What is printed as a result of executing this code segment?
1
1.5
3
20
20.5
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)?
14
40
50
140
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?
int result = secret(4, 4)
int result = secret(4, "4")
double result = secret(4, 4)
double result = secret(4, "4")
double result = secret("4", 4)
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
min(min(p, q), r)
min(p, min(q, r))
min(min(p, q), p)
