All based on Zybooks = AP Java with zylabs
Please answer all questions - no explanation of answers needed
QUESTION 1
char[][] table = new char[10][5];
How many rows are in the array seen in the accompanying figure?
0
5
10
15
QUESTION 2
The standard output object in Java is ____.
output
System.out
Sys.out
System.in
QUESTION 3
The length of the string "first java program" is:
16
18
19
20
1 points
QUESTION 4
The loop condition of a while loop is reevaluated before every iteration of the loop.
True
False
1 points
QUESTION 5
If str1 is “Hello” and str2 is “Hi”, which of the following could not be a result of
str1.compareTo(str2);?
-9
-5
-1
1
1 points
QUESTION 6
Both System.out.println and System.out.print can be used to output a string on the standard
output device.
True
False
1 points
QUESTION 7
In a method call statement, when passing an array as an actual parameter, you use only its name.
True
False
1 points
QUESTION 8
Which of the following is true about a while loop?
The body of the loop is executed at least once.
The logical expression controlling the loop is evaluated before the loop is entered and after the
loop exists.
The body of the loop may not execute at all.
It is a post-test loop
1 points
QUESTION 9
int x, y;
if (x < 4)
y = 2;
else if (x > 4)
{
if (x > 7)
y = 4;
else
y = 6;
}
else
y = 8;
Based on the code above, what is the value of y if x = 9?
2
4
6
8
1 points
QUESTION 10
The array index can be any nonnegative integer less than the array size.
True
False
1 points
QUESTION 11
When a program executes, the first statement to execute is always the first statement in the main
method.
True
False
1 points
QUESTION 12
Java stores two-dimensional arrays in a row order form in computer memory.
True
False
1 points
QUESTION 13
The statement dataType[][][] arrayName; would declare a two-dimensional array.
True
False
1 points
QUESTION 14
All the methods defined in a class must have different names.
True
False
1 points
QUESTION 15
Which of the following is NOT a reserved word in Java?
double
throws
static
num
1 points
QUESTION 16
Given the declaration
int[] list = new int[50];
the statement
System.out.println(list[0] + "..." + list[49]);
outputs all 50 components of the array list.
True
False
1 points
QUESTION 17
In the case of an infinite while loop, the while expression (that is, the loop condition) is always
true.
True
False
1 points
QUESTION 18
Consider the following program.
public class CircleArea
{
static Scanner console = new Scanner(System.in);
static final double PI = 3.14;
public static void main(String[]args)
{
doubler;
double area;
r = console.nextDouble();
area = PI * r * r;
System.out.println("Area = " + area);
}
}
To successfully compile this program, which of the following import statement is required?
import java.io.Scanner;
import java.util.Scanner;
import java.lang.Scanner;
No import statement is required
1 points
QUESTION 19
An identifier can be any sequence of characters and integers.
True
False
1 points
QUESTION 20
A single array can hold elements of many different data types.
True
False
1 points
QUESTION 21
Consider the following program.
// Insertion Point 1
public class CircleArea
{
// Insertion Point 2
static final float PI = 3.14
public static void main(String[]args)
{
//Insertion Point 3
float r = 2.0;
float area;
area = PI * r * r;
System.out.println("Area = " + area);
}
// Insertion Point 4
}
In the above code, where do the import statements belong?
Insertion Point 1
Insertion Point 2
Insertion Point 3
Insertion Point 4
1 points
QUESTION 22
Suppose that x is an int variable. Which of the following expressions always evaluates to false?
(x > 0) || (x <= 0)
(x > 0) || (x == 0)
(x > 0) && ( x <= 0)
(x >= 0) && (x == 0)
1 points
QUESTION 23
What is the value of alpha[4] after the following code executes?
int[] alpha = new int[5];
for (int j = 0; j < 5; j++)
alpha[j] = 2 * j - 1;
one
three
five
seven
1 points
QUESTION 24
If a = 4; and b = 3;, then after the statement a = b; executes, the value of b is 4 and the value of a
is 3.
True
False
1 points
QUESTION 25
The expression !(x <= 0) is true only if x is a positive number.
True
False
1 points
QUESTION 26
In a return method, the last line of the method must be a return statement.
True
False
1 points
QUESTION 27
The expression (int)8.7 evaluates to ____.
8
8.0
9.0
9
1 points
QUESTION 28
A loop is a control structure that causes certain statements to be executed over and over until
certain conditions are met.
True
False
1 points
QUESTION 29
What is stored in alpha after the following code executes?
int[] alpha = new int[5];
for (int j = 0; j < 5; j++)
{
alpha[j] = 2 * j;
if (j % 2 == 1)
alpha[j - 1] = alpha[j] + j;
}
alpha = {0, 2, 4, 6, 8}
alpha = {3, 2, 9, 6, 8}
alpha = {0, 3, 4, 7, 8}
alpha = {0, 2, 9, 6, 8}
1 points
QUESTION 30
Suppose that x and y are int variables and x = 7 and y = 8. After the statement: x = x * y - 2;
executes, the value of x is ____.
42
54
56
58
1 points
QUESTION 31
A counter-controlled loop should be used when the programmer knows the exact number of loop
iterations are needed.
True
False
1 points
QUESTION 32
In Java, a period is used to terminate a statement.
True
False
1 points
QUESTION 33
In Java, return is a reserved word.
True
False
1 points
QUESTION 34
When an array reference is passed to a method, the method can modify the elements of the array
object.
True
False
1 points
QUESTION 35
A local identifier is an identifier that is declared within a method or block and that is visible only
within that method or block.
True
False
1 points
QUESTION 36
An expression such as str.length(); is an example of a(n) ____.
system call
object call
class
method call
1 points
QUESTION 37
Suppose str1 and str2 are String variables. The expression (str1 == str2) determines whether str1
and str2 reference the same String object.
True
False
1 points
QUESTION 38
Just like the nesting of loops, Java allows the nesting of methods.
True
False
1 points
QUESTION 39
Suppose console is a Scanner object initialized with the standard input device. The expression
console.nextInt(); is used to read one int value and the expression console.nextDouble(); is used
to read two int values.
True
False
1 points
QUESTION 40
A compiler translates the assembly language instructions into machine language.
True
False
1 points
QUESTION 41
An identifier can be declared anywhere including within a class, and outside of every method
definition (and every block).
True
False
1 points
QUESTION 42
The following for loop executes 21 times. (Assume all variables are properly declared.)
for (i = 1; i <= 20; i = i + 1)
System.out.println(i);
True
False
1 points
QUESTION 43
Which of the following is the array subscripting operator in Java?
.
{}
new
[]
1 points
QUESTION 44
char[][] table = new char[10][5];
How many columns are in the array seen in the accompanying figure?
0
5
10
15
1 points
QUESTION 45
The digit 0 or 1 is called a ____.
bit
bytecode
Unicode
hexcode
1 points
QUESTION 46
The output of the following Java code is: Stoor.
int count = 5;
System.out.print("Sto");
do
{
System.out.print('o');
count--;
}
while (count >= 5);
System.out.println('r');
True
False
1 points
QUESTION 47
The expression (double)(5 + 4) evaluates to ____.
8
9
9.0
10.0
1 points
QUESTION 48
In Java, !, &&, and || are called logical operators.
True
False
1 points
QUESTION 49
int x, y;
if (x < 4)
y = 2;
else if (x > 4)
{
if (x > 7)
y = 4;
else
y = 6;
}
else
y = 8;
Based on the code above, what is the value of y if x = 4?
2
4
6
8
1 points
QUESTION 50
What is the output of the following code?
int count;
int num = 2;
for (count = 1; count < 2; count++)
{
num = num + 3;
System.out.print(num + " ");
}
System.out.println();
5
5 8
2 5 8
5 8 11
0
5
10
15
Solution
Question 1:
char[][] table = new char[10][5];
How many rows are in the array seen in the accompanying figure?
Answer : 5
Question 2: The standard output object in Java is ____.
Answer : System.out
Question 3: The length of the string "first java program" is:
Answer : 18

All based on Zybooks = AP Java with zylabsPlease answer all questi.pdf

  • 1.
    All based onZybooks = AP Java with zylabs Please answer all questions - no explanation of answers needed QUESTION 1 char[][] table = new char[10][5]; How many rows are in the array seen in the accompanying figure? 0 5 10 15 QUESTION 2 The standard output object in Java is ____. output System.out Sys.out System.in QUESTION 3 The length of the string "first java program" is: 16 18 19 20 1 points QUESTION 4 The loop condition of a while loop is reevaluated before every iteration of the loop. True False 1 points QUESTION 5 If str1 is “Hello” and str2 is “Hi”, which of the following could not be a result of str1.compareTo(str2);? -9 -5 -1 1
  • 2.
    1 points QUESTION 6 BothSystem.out.println and System.out.print can be used to output a string on the standard output device. True False 1 points QUESTION 7 In a method call statement, when passing an array as an actual parameter, you use only its name. True False 1 points QUESTION 8 Which of the following is true about a while loop? The body of the loop is executed at least once. The logical expression controlling the loop is evaluated before the loop is entered and after the loop exists. The body of the loop may not execute at all. It is a post-test loop 1 points QUESTION 9 int x, y; if (x < 4) y = 2; else if (x > 4) { if (x > 7) y = 4; else y = 6; } else y = 8; Based on the code above, what is the value of y if x = 9?
  • 3.
    2 4 6 8 1 points QUESTION 10 Thearray index can be any nonnegative integer less than the array size. True False 1 points QUESTION 11 When a program executes, the first statement to execute is always the first statement in the main method. True False 1 points QUESTION 12 Java stores two-dimensional arrays in a row order form in computer memory. True False 1 points QUESTION 13 The statement dataType[][][] arrayName; would declare a two-dimensional array. True False 1 points QUESTION 14 All the methods defined in a class must have different names. True False 1 points QUESTION 15 Which of the following is NOT a reserved word in Java? double throws static
  • 4.
    num 1 points QUESTION 16 Giventhe declaration int[] list = new int[50]; the statement System.out.println(list[0] + "..." + list[49]); outputs all 50 components of the array list. True False 1 points QUESTION 17 In the case of an infinite while loop, the while expression (that is, the loop condition) is always true. True False 1 points QUESTION 18 Consider the following program. public class CircleArea { static Scanner console = new Scanner(System.in); static final double PI = 3.14; public static void main(String[]args) { doubler; double area; r = console.nextDouble(); area = PI * r * r; System.out.println("Area = " + area);
  • 5.
    } } To successfully compilethis program, which of the following import statement is required? import java.io.Scanner; import java.util.Scanner; import java.lang.Scanner; No import statement is required 1 points QUESTION 19 An identifier can be any sequence of characters and integers. True False 1 points QUESTION 20 A single array can hold elements of many different data types. True False 1 points QUESTION 21 Consider the following program. // Insertion Point 1 public class CircleArea { // Insertion Point 2 static final float PI = 3.14 public static void main(String[]args) { //Insertion Point 3 float r = 2.0; float area; area = PI * r * r; System.out.println("Area = " + area);
  • 6.
    } // Insertion Point4 } In the above code, where do the import statements belong? Insertion Point 1 Insertion Point 2 Insertion Point 3 Insertion Point 4 1 points QUESTION 22 Suppose that x is an int variable. Which of the following expressions always evaluates to false? (x > 0) || (x <= 0) (x > 0) || (x == 0) (x > 0) && ( x <= 0) (x >= 0) && (x == 0) 1 points QUESTION 23 What is the value of alpha[4] after the following code executes? int[] alpha = new int[5]; for (int j = 0; j < 5; j++) alpha[j] = 2 * j - 1; one three five seven 1 points QUESTION 24 If a = 4; and b = 3;, then after the statement a = b; executes, the value of b is 4 and the value of a is 3. True False 1 points QUESTION 25
  • 7.
    The expression !(x<= 0) is true only if x is a positive number. True False 1 points QUESTION 26 In a return method, the last line of the method must be a return statement. True False 1 points QUESTION 27 The expression (int)8.7 evaluates to ____. 8 8.0 9.0 9 1 points QUESTION 28 A loop is a control structure that causes certain statements to be executed over and over until certain conditions are met. True False 1 points QUESTION 29 What is stored in alpha after the following code executes? int[] alpha = new int[5]; for (int j = 0; j < 5; j++) { alpha[j] = 2 * j; if (j % 2 == 1) alpha[j - 1] = alpha[j] + j; } alpha = {0, 2, 4, 6, 8} alpha = {3, 2, 9, 6, 8}
  • 8.
    alpha = {0,3, 4, 7, 8} alpha = {0, 2, 9, 6, 8} 1 points QUESTION 30 Suppose that x and y are int variables and x = 7 and y = 8. After the statement: x = x * y - 2; executes, the value of x is ____. 42 54 56 58 1 points QUESTION 31 A counter-controlled loop should be used when the programmer knows the exact number of loop iterations are needed. True False 1 points QUESTION 32 In Java, a period is used to terminate a statement. True False 1 points QUESTION 33 In Java, return is a reserved word. True False 1 points QUESTION 34 When an array reference is passed to a method, the method can modify the elements of the array object. True False 1 points QUESTION 35 A local identifier is an identifier that is declared within a method or block and that is visible only within that method or block.
  • 9.
    True False 1 points QUESTION 36 Anexpression such as str.length(); is an example of a(n) ____. system call object call class method call 1 points QUESTION 37 Suppose str1 and str2 are String variables. The expression (str1 == str2) determines whether str1 and str2 reference the same String object. True False 1 points QUESTION 38 Just like the nesting of loops, Java allows the nesting of methods. True False 1 points QUESTION 39 Suppose console is a Scanner object initialized with the standard input device. The expression console.nextInt(); is used to read one int value and the expression console.nextDouble(); is used to read two int values. True False 1 points QUESTION 40 A compiler translates the assembly language instructions into machine language. True False 1 points QUESTION 41 An identifier can be declared anywhere including within a class, and outside of every method definition (and every block).
  • 10.
    True False 1 points QUESTION 42 Thefollowing for loop executes 21 times. (Assume all variables are properly declared.) for (i = 1; i <= 20; i = i + 1) System.out.println(i); True False 1 points QUESTION 43 Which of the following is the array subscripting operator in Java? . {} new [] 1 points QUESTION 44 char[][] table = new char[10][5]; How many columns are in the array seen in the accompanying figure? 0 5 10 15 1 points QUESTION 45 The digit 0 or 1 is called a ____. bit bytecode Unicode hexcode 1 points QUESTION 46 The output of the following Java code is: Stoor. int count = 5;
  • 11.
    System.out.print("Sto"); do { System.out.print('o'); count--; } while (count >=5); System.out.println('r'); True False 1 points QUESTION 47 The expression (double)(5 + 4) evaluates to ____. 8 9 9.0 10.0 1 points QUESTION 48 In Java, !, &&, and || are called logical operators. True False 1 points QUESTION 49 int x, y; if (x < 4) y = 2; else if (x > 4) { if (x > 7) y = 4; else y = 6;
  • 12.
    } else y = 8; Basedon the code above, what is the value of y if x = 4? 2 4 6 8 1 points QUESTION 50 What is the output of the following code? int count; int num = 2; for (count = 1; count < 2; count++) { num = num + 3; System.out.print(num + " "); } System.out.println(); 5 5 8 2 5 8 5 8 11 0 5 10 15 Solution Question 1: char[][] table = new char[10][5];
  • 13.
    How many rowsare in the array seen in the accompanying figure? Answer : 5 Question 2: The standard output object in Java is ____. Answer : System.out Question 3: The length of the string "first java program" is: Answer : 18