Programming Exam 2

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Which loop should you use if... 1- Do not want the loop to iterate if the condition is false? 2- Want the loop to iterate at least once? 3- Want to know the exact number of times the loop should iterate?

1- while loop 2- do-while loop 3- for loop

What do the following statements produce? int x = 10; int y = 5; x += y; System.out.println(x);

15

What do the following statements produce? int x = 10; int y = 5; x = y++; System.out.println(x);

5

The binary search algorithm... a. is less efficient than the sequential search algorithm b. will cut the portion of the array being searched in half each time it fails to locate the search value c. will have a maximum number of comparisons equal to the number of elements in the array d. will, normally, have the number of comparisons that is half the number of elements in the array

B

The sequential search algorithm... a. returns 1 if the value being searched for is found or -1 if the value is not found b. requires the array to be ascending order c. uses a loop to sequentially step through an array, starting with the first element d. All of these are true

C

What is the value of scores[2][3] in the following array? int[][] scores = { {88, 80, 79, 92}. {75, 84, 93, 80}, {98, 95, 92, 94}, {91, 84, 88, 96} }; a. 95 b. 84 c. 94 d. 93

C

What would be the result after the following code is executed? int[] numbers = {40, 3, 5, 7, 8, 12, 10}; int value = numbers[0]; for (int i = 1; i < numbers.length; i++) { if (numbers[i] < value) value = numbers[i]; } a. The value variable will contain the average of all the values in the numbers array. b. The value variable will contain the sum of all the values in the numbers array. c. The value variable will contain the lowest value in the numbers array. d. The value variable will contain the highest value in the numbers array.

C

Which of the following ArrayList class methods is used to insert an item at a specific location in an ArrayList? a. set b. store c. add d. insert

C

A single copy of a class's static field is shared across all instances of the class

True

An ArrayList object automatically expands in size to accommodate the items stored in it.

True

Objects in an array are accessed with subscripts, just like any other data type in an array.

True

The String[] args parameter in the main method header allows the program to receive arguments from the operating system command-line.

True

To determine if two arrays are equal you must compare each of the elements of the two arrays.

True

When a class contains a static method, it isn't necessary for an instance of the class to be created to execute the method.

True

When two methods have the same name but different signatures, they are said to be overloaded.

True

A(n) _______________ clause must be is added to the end of the method header of a method that uses the IO classes discussed in chapter 5.10

throws IOException

The PrintWriter class is used to _______ _____ a file.

Write to

A method's signature consists of... a. the method name and the parameter list b. the return type, the method name, and the parameter list c. the size of the method in memory d. the return type and the method name

A

Given the following method header, what will be returned from the method? public Rectangle getRectangle() a. the address of an object of the Rectangle class b. the values stored in the data members of the Rectangle object c. a null value d. an object that is contained in the class Rectangle

A

The FileWriter class is used to ______ _____ a file.

Append to

What would be the result after the following code is executed? int[] numbers = {50, 10, 15, 20, 25, 100, 30}; int value = 0; for (int i = 1; i < numbers.length; i++) value += numbers[i]; a. The value variable will contain the average of all the values in the numbers array. b. The value variable will contain the sum of all the values in the numbers array. c. The value variable will contain the lowest value in the numbers array. d. The value variable will contain the highest value in the numbers array.

B

What would be the result of executing the following code? int[] x = {0, 1, 2, 3, 4, 5}; a. An array of 6 values, all initialized to 0 and referenced by the variable x will be created. b. An array of 6 values, ranging from 0 through 5 and referenced by the variable x will be created. c. The variable x will contain the values 0 through 5. d. A compiler error will occur.

B

Which of the following methods returns a string representing all of the items stored in an ArrayList object? a. show b. toString c. print d. getList

B

A search algorithm.... a. arranges elements in ascending order b. arranges elements in descending order c. is used to locate a specific item in a collection of data d. is rarely used with arrays

C

Given the following two-dimensional array declaration, which statement is true? int[][] numbers = new int[6][9]; a. The numbers array has 54 rows. b. The numbers array has 15 rows. c. The numbers array has 6 rows and 9 columns. d. The numbers array has 6 columns and 9 rows.

C

Of the following, which would be considered the no-arg constructor for the Rectangle class? a. public Rectangle(int len, int width) b. public Rectangle(double len, double width) c. public Rectangle() d. public Rectangle(length, width)

C

An array of String objects... a. is arranged the same as an array of primitive objects b. is compressed to four bytes for each element c. must be initialized when the array is declared d. consists of an array of references to String objects

D

What will be the result after the following code is executed? final int ARRAY_SIZE = 5; float[] x = float[ARRAY_SIZE]; for (i = 1; i <= ARRAY_SIZE; i++) { x[i] = 10.0; } a. A runtime error will occur. b. All the values in the array will be initialized to 10.0. c. All the values in the array except the first will be set to 10.0. d. The code contains a syntax error and will not compile.

D

When an array is passed to a method... a. it is passed just as any other object would be passed b. the method has direct access to the original array c. a reference to the array is passed d.All of these are true

D

A sorting algorithm is used to locate a specific item in a larger collection of data.

False

Provide a statement instantiating a FileWriter object

FileWriter appendFile = new FileWriter("Appendfilename.txt", true);

Explain the difference between pre increment ++x and post increment x++.

Pre increment is used to increase the value by 1 before assigning a value to the variable. Post increment is used to increase the value by 1 after assigning a value to the variable.

The File class is used to _______ _____ a file.

Read from


Kaugnay na mga set ng pag-aaral

PrepU Nursing Process and Assessment

View Set

nursing process /diagnosis questions (NCLEX styled)

View Set

chapter 5, Chapter 8, Chapter 13, Chapter 9, Chapter 3, Chapter 4, Chapter 6, Chapter 10, Chapter 11, Chapter 18, Chapter 19, Chapter 17, Chapter 16, Chapter 20, Chapter 14, Chapter 15

View Set

PRELUDE: AND JUST WHAT IS GEOLOGY?

View Set

intro test 4 ch. 5 point questions

View Set

Head First PMP 4th Edition - project schedule management Exam Questions

View Set

ÖLKƏLƏR VƏ PAYTAXTLARI /// B HƏRFİ

View Set

Psych 726 - Chapter 10 - Assessment of Aptitude

View Set