Font size
WorksheetsAP CS A Midterm Review
Total questions: 37
Worksheet time: 41mins
What is output by the code?
0
1
2
3
4
What is output by the code?
0
1
2
3
4
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
0 0 0 1 0
0 0 1 0 0
0 1 0 0 0
1 0 0 0 0
0 0 1 0 0
1 1 1 1 1
0 0 1 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 1 0
1 1 1 1 1
0 0 0 1 0
1. Consider the following code segment.
System.out.println("\"This is my output.\"");
This is my output.
"This is my output."
"\"This is my output.\""
\"This is my output.\"
Nothing, it will produce an error.
Which of the following is correct
public class MyFile {
Public class MyFile {
public Class MyFile {
Which of the following is NOT an escape sequence?
\n
/n
\\
//
The body of a method definition is contained within a set of ______________.
parentheses
rectangle brackets
curly braces
angle brackets
Methods that contain the _______ keyword in the data type position do not return any data, so they can simply be called without being part of a larger statement.
void
static
public
boolean
What is the output?
String s="hello";
s.substring(1,3);
"ell"
"hel"
"he"
"el"
What is the output?
String s = "hello";
s.substring(1);
"h"
"e"
"ello"
"hello"
What is the output?
String s = "hello";
s.substring(1,7);
"hello"
""
index out of bounds
"ello "
What is the output?
String s = "hello";
s.substring(2,2);
""
"l"
"e"
index out of bounds
What are the values of x, y, and z after this code executes?
x = 6, y = 2.5, z = 2
x = 4, y = 2.5, z = 2
x = 6, y = 2, z = 3
x = 4, y = 2.5, z = 3
x = 4, y = 2, z = 3
What are the values of x, y, and z after this code executes?
x = -1, y = 1, z = 4
x = -1, y = 2, z = 3
x = -1, y = 2, z = 2
x = -1, y = 2, z = 2
x = -1, y = 2, z = 4
Which of the following returns the correct average when 3 values had been added to an integer total?
(double) (total / 3);
total / 3;
(double) total / 3;
Evaluate 2 % 3
2
0
3
1
Evaluate 1 / 3
0.3333333333333333
0
It will give a run-time error
0.3
It will give a compile-time error
Evaluate 2 + 3 * 5 - 1
24
14
This will give a compile time error.
16
What is the value of b after this code executes?
9.6982
12
10
9
Evaluate
(double) 5 / 2
2.0
2
2.5
error - incompatible types
Evaluate
(double) ( 7 / 2 )
3
3.0
3.5
error - incompatible types
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
What does the expression "Nomnomnom yummy turkey".indexOf("Thank") evaluate to?
Thank
Nomnomnom
turkey
-1
0
Which of the following would correctly define and instantiate a Scanner?
Scanner kb = Scanner(in);
Scanner kb = new Scanner(in);
Scanner new kb = Scanner(in);
Scanner kb = new kb(in);
none of these
Which of the following Scanner methods can be used to read in a int?
nextInt()
next()
nextInts()
nextDouble()
nextInteger()
Which of the following Scanner methods can be used to read in a double?
nextInt()
nextDble()
nextDouble()
next()
nextLine()
Which of the following Scanner methods can be used to read in a String?
nextInt()
nextWord()
nextDouble()
next()
nextLine()
Which of the following Scanner methods can be used to read in a line of words?
nextInt()
nextDble()
nextDouble()
next()
nextLine()
Given the following statement, var must be defined as which of the following types?
var = keyboard.nextInt();
short
String
double
int
Given the following statement, var must be defined as which of the following types?
var = keyboard.nextLine();
short
String
double
int
