Java Foundations 3rd Edition John Lewis Test Bank download
Java Foundations 3rd Edition John Lewis Test Bank download
Bank download
https://testbankdeal.com/product/java-foundations-3rd-edition-
john-lewis-test-bank/
https://testbankdeal.com/product/java-foundations-3rd-edition-lewis-
solutions-manual/
https://testbankdeal.com/product/java-software-solutions-foundations-
of-program-design-7th-edition-lewis-test-bank/
https://testbankdeal.com/product/java-software-solutions-foundations-
of-program-design-7th-edition-lewis-solutions-manual/
https://testbankdeal.com/product/structural-analysis-si-edition-4th-
edition-kassimali-solutions-manual/
https://testbankdeal.com/product/economics-of-money-banking-and-
financial-markets-global-11th-edition-mishkin-solutions-manual/
https://testbankdeal.com/product/introduction-to-criminal-justice-a-
balanced-approach-1st-edition-payne-test-bank/
https://testbankdeal.com/product/canadian-income-
taxation-2017-2018-canadian-20th-edition-buckwold-test-bank/
https://testbankdeal.com/product/payroll-accounting-2014-24th-edition-
bieg-test-bank/
Essentials of International Relations 8th Edition Mingst
Test Bank
https://testbankdeal.com/product/essentials-of-international-
relations-8th-edition-mingst-test-bank/
Java Foundations: Introduction to Program Design & Data Structures, 3/e
John Lewis, Peter J. DePasquale, Joseph Chase
Test Bank: Chapter 7
Chapter 7: Arrays
a) -1
b) 0
c) 1
d) 2
e) you can declare an array to have any indexes you choose
Answer: b
Explanation: In Java, the array indexes are from 0 to one less than the length of the array.
Answer: a
Explanation: The code represents the declaration and initialization of an array that will hold 50 integers. The
indexes of this array will begin at 0 and end at 49.
a) The integer value 2 will be assigned to the last index in the array.
b) The integer value 25 will be assigned to the second index in the array.
c) The integer value 25 will be assigned to the third value in the array.
d) This code will result in a compile-time error.
e) This code will result in a run-time error.
Answer: e
Explanation: This code will throw an ArrayIndexOutOfBoundsException, since the last index in this array will
be 24. This causes a run-time error.
1
Addison-Wesley © 2014
Java Foundations: Introduction to Program Design & Data Structures, 3/e
John Lewis, Peter J. DePasquale, Joseph Chase
Test Bank: Chapter 7
a) 26
b) 24
c) 25
d) This code will result in a compile time error.
e) This code will result in a run time error.
Answer: c
Explanation: Note that the length instance variable can be accessed directly. Therefore this will not result in any
errors. The array has length 25, and therefore the code will output 25.
Answer: d
Explanation: All three of these are valid array declarations. Choice b uses an alternate syntax. Choice c uses an
initializer list to initialize the array.
Answer: b
Explanation: Arrays are passed to methods by reference. This means that if the content of the array is changed in a
method, the change will be reflected in the calling method.
7) Suppose we have an array of String objects identified by the variable names. Which of the following for loops will not
correctly process each element in the array.
Answer: c
Explanation: Choice c will not process each element correctly due to a syntax error. The length variable is not a
method and, therefore, does not have parenthesis after it. Choice b is an example of using a foreach loop to process an
array, and choice a is a correct for loop.
8) Which of the following statements will assign the first command-line argument sent into a Java program to a variable
2
Addison-Wesley © 2014
Java Foundations: Introduction to Program Design & Data Structures, 3/e
John Lewis, Peter J. DePasquale, Joseph Chase
Test Bank: Chapter 7
called argument?
a) argument = System.getFirstArgument();
b) argument = System.getArgument[1];
c) argument = System.getArgument[0];
d) argument = args[0];
e) argument = args[1];
Answer: d
Explanation: Choice d is the correct answer. The System object does not have any methods called
getFirstArgument or getArgument, and the args array's index starts at 0. Therefore the other choices are incorrect.
9) Which of the following method declarations correctly defines a method with a variable length parameter list?
Answer: b
Explanation: The only choices with valid syntax are choice a and choice b. Choice a represents a method
declaration with a single parameter, which is a reference to an array. Choice b correctly represents a valid declaration for a
method with a variable length parameter list.
a) int[][] matrix;
b) int[2] matrix;
c) int[]** matrix;
d) int[] matrix;
e) none of these are correct
Answer: a
Explanation: Choice a is the only valid declaration for a two-dimensional array. Choices b and c contain invalid
Java syntax, and choice d is a valid declaration for a single dimensional array.
11) Which of the following lines of code accesses the second element of the first array in a two-dimensional array of
integers, numbers, and stores the result in a variable called num?
a) num = numbers[1][2];
b) num = numbers[0][1];
c) num = numbers.getElement(1, 2);
d) num = numbers.getElement(0, 1);
e) none of the above are correct
Answer: b
Explanation: Choice b accesses the second element of the first array. Choice a accesses the third element of the
3
Addison-Wesley © 2014
Java Foundations: Introduction to Program Design & Data Structures, 3/e
John Lewis, Peter J. DePasquale, Joseph Chase
Test Bank: Chapter 7
Answer: e
Explanation: None of the statements about two-dimensional arrays are true.
13) What is the precedence of the index operator ( [ ] ) relative to other operators in Java?
Answer: d
Explanation: The index operator has the highest precedence of all Java operators.
14) Every Java array is a(n) _________________, so it is possible to use a foreach loop to process each element in the
array.
a) object
b) iterator
c) class
d) operator
e) none of the above
Answer: b
Explanation: Every Java array is an iterator, therefore a foreach loop can be used to process each element in the
array.
15) Multi-dimensional arrays that contain arrays of different lengths in any one dimension are called _________________.
a) ragged arrays
b) static arrays
c) two-dimensional arrays
d) constant arrays
e) overloaded arrays
Answer: a
Explanation: Ragged arrays are multi-dimensional arrays that contain arrays at the same dimension with differing
lengths.
4
Addison-Wesley © 2014
Java Foundations: Introduction to Program Design & Data Structures, 3/e
John Lewis, Peter J. DePasquale, Joseph Chase
Test Bank: Chapter 7
True/False Questions:
1) In Java, array indexes begin at 0 and end at one less than the length of the array.
Answer: True
Explanation: For an array of length n, the indexes begin at 0 and end at n – 1 in Java.
Answer: False
Explanation: An array declared as above can only store 10 elements.
6) If a program attempts to access an element outside of the range of the array indexes, a run-time error will occur.
Answer: True
Explanation: If a program attempts to access an element outside of the range of the array indexes, an
ArrayOutOfBoundsException will be thrown at run-time.
9) It is possible for a method to have a variable length parameter list, meaning that the method can take in any number of
parameters of a specified data type.
Answer: True
Explanation: Java supports variable length parameter lists for methods.
10) In Java it is not possible to have arrays of more than two dimensions.
Answer: False
5
Addison-Wesley © 2014
Java Foundations: Introduction to Program Design & Data Structures, 3/e
John Lewis, Peter J. DePasquale, Joseph Chase
Test Bank: Chapter 7
Explanation: It is possible to have arrays of any dimension in Java. It is not common, however, for these types of
arrays to be used in object-oriented programs.
6
Addison-Wesley © 2014
Java Foundations: Introduction to Program Design & Data Structures, 3/e
John Lewis, Peter J. DePasquale, Joseph Chase
Test Bank: Chapter 7
Answer: Arrays are passed to methods by reference. This means that a reference to the original array is sent into
the method. Therefore any changes that are made to the array in the method will be reflected in the original array in the
calling method.
2) Write the declaration for an array of doubles called averages that is initialized with an initializer list.
Answer:
3) Write the declaration for a two-dimensional array of integers that can be thought of as a table with three rows and three
columns. Assign the value 3 to the cell that is in the second row and the third column.
Answer:
4) Write a loop that cycles through an array of String objects called names and prints them out, one per line. Your loop
should not use a foreach loop.
Answer:
5) Write a loop that cycles through an array of String objects called names and prints out the ones that start with a vowel,
one per line. Your loop should use a foreach loop.
Answer:
for(String n : names)
if(n.charAt(0) == 'A' || n.charAt(0) == 'a' ||
n.charAt(0) == 'E' || n.charAt(0) == 'e' ||
n.charAt(0) == 'I' || n.charAt(0) == 'i' ||
n.charAt(0) == 'O' || n.charAt(0) == 'o' ||
n.charAt(0) == 'U' || n.charAt(0) == 'u')
System.out.println(n);
6) Write a method that accepts an array of integers as a parameter and returns the sum of all of the integers in the array.
Answer:
7
Addison-Wesley © 2014
Java Foundations: Introduction to Program Design & Data Structures, 3/e
John Lewis, Peter J. DePasquale, Joseph Chase
Test Bank: Chapter 7
int sum = 0;
for(int i = 0; i < array.length; i++)
sum += array[i];
return sum;
}
7) Write a method called doubleSize that accepts an integer array as a parameter and returns a reference to a new integer
array that is twice as long and contains all of the elements of the first array in the same positions.
Answer:
return newArray;
}
8) Write a method called average that accepts an array of floating point numbers and returns their average.
Answer:
9) Write a method called containsPair that accepts an array of integers as a parameter and returns true if it contains two
integers that are equal.
Answer:
return false;
}
8
Addison-Wesley © 2014
Java Foundations: Introduction to Program Design & Data Structures, 3/e
John Lewis, Peter J. DePasquale, Joseph Chase
Test Bank: Chapter 7
10) Write a method that takes in an arbitrary number of String objects, and then prints out all of them that have over 10
characters.
Answer:
11) Write a method that takes in at least one integer and returns the largest of all integer parameters sent in.
Answer:
return currentLargest;
}
12) Write a method that accepts an array of integers as a parameter and returns a reference to an array that contains the
even numbers in the array original array. The returned array should have a size equal to the number of even numbers in the
original array.
Answer:
int evenArrayIndex = 0;
9
Addison-Wesley © 2014
Java Foundations: Introduction to Program Design & Data Structures, 3/e
John Lewis, Peter J. DePasquale, Joseph Chase
Test Bank: Chapter 7
evenArrayIndex++;
}//end if
}//end for
}
13) Write a short program that accepts an arbitrary number of command line arguments, and prints out those containing the
character 'z'.
Answer:
14) Write a line of code that initializes a two-dimensional array of integers using an initializer list.
Answer:
15) Write a method that accepts an array of integers and returns the smallest value in the list.
Answer:
return currentSmallest;
}
10
Addison-Wesley © 2014
Visit https://testbankdead.com
now to explore a rich
collection of testbank,
solution manual and enjoy
exciting offers!
Other documents randomly have
different content
The Project Gutenberg eBook of A servant of
Satan: Romantic career of Prado the assassin
This ebook is for the use of anyone anywhere in the United States
and most other parts of the world at no cost and with almost no
restrictions whatsoever. You may copy it, give it away or re-use it
under the terms of the Project Gutenberg License included with this
ebook or online at www.gutenberg.org. If you are not located in the
United States, you will have to check the laws of the country where
you are located before using this eBook.
Language: English
A SERVANT OF SATAN.
Romantic Career of PRADO the Assassin.
From Notes Communicated to a Friend on the Eve of His Execution.
The Great Riddle which the French Police were Unable to Solve.
By LOUIS BERARD.
NEW YORK:
STREET & SMITH, Publishers,
31 Rose Street.
testbankdeal.com