Full Practice Test Bank: Data Structures and
Algorithms in Java, 6th Edition
Authors: Michael T. Goodrich, Roberto
Tamassia, Michael H. Goldwasser
Publisher: Wiley
Edition: 6th Edition (2014)
ISBN: 978-1-118-77133-4
Content Coverage: All 15 chapters, with 250+
multiple-choice questions, verified answers,
and detailed rationales.
CHAPTER 1: JAVA PRIMER
1
,Q1. Which of the following is a primitive data
type in Java?
A) String
B) Integer
C) int
D) Array
Answer: C) int
Rationale: `int` is one of the eight primitive
data types in Java (byte, short, int, long, float,
double, boolean, char). `String` and `Integer`
are classes (reference types), and arrays are
objects.
Q2. What is the range of a Java `int`?
2
,A) -128 to 127
B) -32,768 to 32,767
C) Approximately -2.1 billion to +2.1 billion
D) Approximately -9.2 quintillion to +9.2
quintillion
Answer: C) Approximately -2.1 billion to +2.1
billion
Rationale: A Java `int` is a 32-bit signed
integer, giving a range of -2,147,483,648 to
2,147,483,647.
Q3. Which of the following correctly declares
and initializes an array of 10 integers?
A) int[] arr = new int(10);
B) int arr[] = new int[10];
3
, C) int[] arr = int[10];
D) array<int> arr = new array(10);
Answer: B) int arr[] = new int[10];
Rationale: In Java, arrays are declared using
`type[] name` or `type name[]`, and
instantiated with `new type[size]`. Option A is
incorrect because parentheses are used for
constructors of classes, not arrays.
Q4. What will be the output of the following
code fragment?
```java
int a = 0;
int b = 10;
while (a < b) {
4
Algorithms in Java, 6th Edition
Authors: Michael T. Goodrich, Roberto
Tamassia, Michael H. Goldwasser
Publisher: Wiley
Edition: 6th Edition (2014)
ISBN: 978-1-118-77133-4
Content Coverage: All 15 chapters, with 250+
multiple-choice questions, verified answers,
and detailed rationales.
CHAPTER 1: JAVA PRIMER
1
,Q1. Which of the following is a primitive data
type in Java?
A) String
B) Integer
C) int
D) Array
Answer: C) int
Rationale: `int` is one of the eight primitive
data types in Java (byte, short, int, long, float,
double, boolean, char). `String` and `Integer`
are classes (reference types), and arrays are
objects.
Q2. What is the range of a Java `int`?
2
,A) -128 to 127
B) -32,768 to 32,767
C) Approximately -2.1 billion to +2.1 billion
D) Approximately -9.2 quintillion to +9.2
quintillion
Answer: C) Approximately -2.1 billion to +2.1
billion
Rationale: A Java `int` is a 32-bit signed
integer, giving a range of -2,147,483,648 to
2,147,483,647.
Q3. Which of the following correctly declares
and initializes an array of 10 integers?
A) int[] arr = new int(10);
B) int arr[] = new int[10];
3
, C) int[] arr = int[10];
D) array<int> arr = new array(10);
Answer: B) int arr[] = new int[10];
Rationale: In Java, arrays are declared using
`type[] name` or `type name[]`, and
instantiated with `new type[size]`. Option A is
incorrect because parentheses are used for
constructors of classes, not arrays.
Q4. What will be the output of the following
code fragment?
```java
int a = 0;
int b = 10;
while (a < b) {
4