Notes MIS301 Exam 3

¡Supera tus tareas y exámenes ahora con Quizwiz!

If x is an int where x = 0, what will x be after the following loop terminates? while (x < 100) x *= 2; A) 2 B) 64 C) 100 D) 128 E) none of the above, this is an infinite loop

E

The idea that program instructions execute in order (linearly) unless otherwise specified through a conditional statement is known as A) boolean execution B) conditional statements C) try and catch D) sequentiality E) flow of control

E

if (a > 0) if (b < 0) x = x + 5; else if (a > 5) x = x + 4; else x = x + 3; else x = x + 2; If x is currently 0, a = 1 and b = -1, what will x become after the above statement is executed? A) 0 B) 2 C) 3 D) 4 E) 5

E

A _________________ array is an array of arrays. It can be thought of as having rows and columns

Two-dimensional

The default capacity of an ArrayList is ____ items.

10

Assume that BankAccount is a predefined class and that the declaration BankAccount[ ] firstEmpireBank; has already been performed. Then the following instruction reserves memory space for firstEmpireBank = new BankAccount[1000];

1000 reference variables, each of which point to a single BankAccount entry

Assume that BankAccount is a predefined class and that the declaration BankAccount[ ] firstEmpireBank; has already been performed. Then the following instruction reserves memory space for firstEmpireBank = new BankAccount[1000];

1000 reference variables, each of which point to a single BankAccount entry.

If an int array is passed as a parameter to a method, which of the following would adequately define the parameter list for the method header?

(int[ ] a)

For the questions below, assume values is an int array that is currently filled to capacity, with the following values: 9 12 4 8 20 15 What is the value of values.length?

6

For the questions below, assume values is an int array that is currently filled to capacity, with the following values: 9 12 4 8 20 15 What is returned by values[3]?

8

Assume that count is 0, total is 20 and max is 1. The following statement will do which of the following? if (count != 0 && total / count > max) max = total / count; A) The condition short circuits and the assignment statement is not executed B) The condition short circuits and the assignment statement is executed without problem C) The condition does not short circuit causing a division by zero error D) The condition short circuits so that there is no division by zero error when evaluating the condition, but the assignment statement causes a division by zero error E) The condition will not compile because it uses improper syntax

A

Every Interator A) has a hasNext( ) method B) has a hasFirst( ) method C) has a hasNextInt( ) method D) has a isEmpty( ) method E) none of the above

A

If a break occurs within the innermost loop of a nested loop that is three levels deep A) when the break is encountered just the innermost loop is "broken" B) when the break is encountered, all loops are "broken" and execution continues from after the while statement (in our example) C) when the break is encountered, all but the outermost loops are broken, and execution continues from the next iteration of the while loop (in our example) D) this is a syntax error unless there are break or continue statements at each loop level E) none of the above

A

What is wrong, logically, with the following code? if (x > 10) System.out.println("Large"); else if (x > 6 && x <= 10) System.out.println("Medium"); else if (x > 3 && x <= 6) System.out.println("Small"); else System.out.println("Very small"); A) There is no logical error, but there is no need to have (x <= 10) in the second conditional or (x <= 6) in the third conditional B) There is no logical error, but there is no need to have (x > 6) in the second conditional or (x > 3) in the third conditional C) The logical error is that no matter what value x is, "Very small" is always printed out D) The logical error is that no matter what value x is, "Large" is always printed out E) There is nothing wrong with the logic at all

A

An _________ can hold multiple values of the same data type simultaneously.

Array

__________________ is a class in the Java API that is similar to an array and allows you to store objects. Unlike an array, an __________________ object's size is automatically adjusted to accommodate the number of items stored in it.

ArrayList

As introduced in the Software Failure, the terminology "risk analysis" means A) how willing are you to risk the loss of several key programmers working on your project B) how much are you willing to risk that a particular piece of software you are developing still contains an error or errors C) how willing are you to risk that your software will fail once implemented D) how willing are you to risk that the machines on which your software will run will not work E) none of the above

B

Consider the following outline of a nested if-else structure which has more if clauses than else clauses. Which of the statements below is true regarding this structure? if (condition1) if (condition2) statement1; else statement2; A) syntactically it is invalid to have more if clauses than else clauses B) statement2 will only execute if condition1 is false and condition2 is false C) statement2 will only execute if condition1 is true and condition2 is false D) statement2 will only execute if condition1 is false, it does not matter what condition2 is E) statement2 will never execute

B

The break statement does which of the following? A) ends the program B) transfers control out of the current control structure such as a loop or switch statement C) ends the current line of output, returning the cursor D) denotes the ending of a switch statement E) indicates the end of line when using System.out.print

B

Which of the sets of statements below will add 1 to x if x is positive and subtract 1 from x if x is negative but leave x alone if x is 0? A) if (x > 0) x++; else x--; B) if (x > 0) x++; else if (x < 0) x--; C) if (x > 0) x++; if (x < 0) x--; else x = 0; D) if (x == 0) x = 0; else x++; x--; E) x++; x--;

B

if (a > 0) if (b < 0) x = x + 5; else if (a > 5) x = x + 4; else x = x + 3; else x = x + 2; If x is currently 0, a = 0 and b = -5, what will x become after the above statement is executed? A) 0 B) 2 C) 3 D) 4 E) 5

B

To initialize a String array names to store the three Strings "Huey", "Duey" and "Louie", you would do

B) String[ ] names = {"Huey", "Duey", "Louie"};

if (a > 0) if (b < 0) x = x + 5; else if (a > 5) x = x + 4; else x = x + 3; else x = x + 2; If x is currently 0, a = 5 and b = 5, what will x become after the above statement is executed? A) 0 B) 2 C) 3 D) 4 E) 5

C

An ArrayList has a _______, which is the number of items it can hold without increasing its size.

Capacity

Assume that x and y are int variables with x = 5, y = 3, and a and d are char variables with a = 'a' and d = 'A', and examine the following conditions: Condition 1: (x < y && x > 0) Condition 2: (a != d || x != 5) Condition 3: !(true && false) Condition 4: (x > y || a == 'A' || d != 'A') A) All 4 Conditions are true B) Only Condition 2 is true C) Condition 2 and Condition 4 are true only D) Conditions 2, 3 and 4 are all true, Condition 1 is not E) All 4 Conditions are false

D

Consider the following code that will assign a letter grade of 'A', 'B', 'C', 'D', or 'F' depending on a student's test score. if (score >= 90) grade = 'A'; if (score >= 80) grade = 'B'; if (score >= 70) grade = 'C'; if (score >= 60) grade = 'D'; else grade = 'F'; A) This code will work correctly in all cases B) This code will work correctly only if grade >= 60 C) This code will work correctly only if grade < 60 D) This code will work correctly only if grade < 70 E) This code will not work correctly under any circumstances

D

How many times will the following loop iterate? int x = 10; while (x > 0) { System.out.println(x); x--; } A) 0 times B) 1 time C) 9 times D) 10 times E) 11 times

D

If x is an int where x = 1, what will x be after the following loop terminates? while (x < 100) x *= 2; A) 2 B) 64 C) 100 D) 128 E) none of the above, this is an infinite loop

D

27 bs question. Why is that one students code better than the rest of ours?

D, I'm guessing.

Of the following if statements, which one correctly executes three instructions if the condition is true? A) if (x < 0) a = b * 2; y = x; z = a - y; B) { if (x < 0) a = b * 2; y = x; z = a - y; } C) if { (x < 0) a = b * 2; y = x; z = a - y ; } D) if (x < 0) { a = b * 2; y = x; z = a - y; } E) B, C and D are all correct, but not A

D

Although methods may be declared with a variable length parameter list, class constructors cannot.

False

Array have a built in toString method that returns all of the elements in the array as one string with "/n" inserted betweeen each element

False

In a two dimensional array both dimensions must have the same number of elements as in[10][10]

False

In a two-dimensional array, both dimensions must have the same number of elements, as in[10][10].

False

It is possible to sort an array of int,float,double,or string, but not an array of an object class such as a CD class.

False

Java arrays can store primitive types and Strings, but cannot store any other type of Object other than Strings.

False

Javba arrays can store primitive types and string but cannot store any other type of object other than strings

False

Just as arrays can only have a fixed number of elements, set at the time the array is declared a parameter list also can only have a fixed number of elemtns set at the time the method is declared.

False

T/F Although methods may be declared with a variable length parameter list, class constructors cannot

False

To swap the 3rd and 4th elements in the int array values you would do: values[3]=values[4] values[4]=values[3]

False

True or False: Once an array is created, its size can be changed.

False

An array's length is a ________. -You do not write a set of parentheses after its name.

Field

_________ parameters are actually arrays and can take any number of arguments. They look like this: public static int sum (*int... numbers*){}

vararg

Make sure to read page 501 about binary searches, there was too much info to put on a card. (type yes if you get this)

yes

True or False: Two-dimensional arrays are arrays of one-dimensional arrays. The length field of the array gives the number of rows in the array. Each row has a length constant tells how many columns is in that row. Each row can have a different number of columns.

True

What does the following code do? Assume list is an array of int values, temp is some previously initialized int value, and c is an int initialized to 0. for (int j = 0; j < list.length; j++) if (list[j] < temp) c++;

It counts the number of elements in list that are less than temp

Consider the array declaration and instantiation: int[ ] arr = new int[5]; Which of the following is true about arr?

It stores 5 elements with legal indices between 0 and 4

True or False: Typically, if the amount of data that an array must hold is unknown: -Size the array to the largest expected number of elements. -Use a counting variable to keep track of how much valid data is in the array.

True

A String's length is a __________. -You write the parentheses after the name of the String class's length method.

Method

When the rows of a two-dimensional array are of different lengths, the array is known as a ___________ array.

Ragged

A __________ algorithm is a method of locating a specific item in a larger collection of data.

Search

The ____________ sort works like this: The smallest value in the array is located and moved to element 0. Then the next smallest value is located and moved to element 1. This process continues until all of the elements have been placed in the proper order.

Selection

The _________ search algorithm uses a loop to step through an array starting with the first element. It compares each element with the value being searched for, and stops when the value is found or the end of the array is encountered.

Sequential

True or False: When a single element of an array is passed to a method it is handled like any other variable. More often you will want to write methods to process array data by passing the entire array, not just one element at a time.

True

numbers = new int[6]; The number inside the brackets is the array's ______________. It indicates the number of ___________, or values the array can hold. (2 answers)

Size declarator, elements

A __________ algorithm is used to arrange data into some order. A ____________ algorithm is a method of locating a specific item in a larger collection of data.(2 answers)

Sorting, search

Each element in an array is assigned a number known as a _____________.

Subscript

True or False: You cannot change the value of an array's length field.

True

True or False: This is not the way to copy an array. int[] array1 = { 2, 4, 6, 8, 10 }; int[] array2 = array1; // This does not copy array1.

True

A Java main method uses the parameter (String[]variable) so that a user can run the program and suppy "command lines" parameters since the parameter is a string array howerver the user does not have to supply any parameters

True

An array index cannot be a float,double,Boolean, or string

True

An array when instantiated is fixed in size but an arrayList can dynamically change in size when new elements are added to it.

True

An array, when instantiated, is fixed in size, but an ArrayList can dynamically change in size when new elements are added to it.

True

If the following statement is performed: CD[]=myCollection=new CD[200]; where CD is a previously defined class, then myCollection[5] is a CD object

True

In java an array can only store one type of data for instance you cannot create an array that stores both double and string value

True

In java, an array can only store one type of data. You cannot create an array that stores both double and String values

True

True or False: An array can store any type of data but only one type of data at a time.

True

True or False: An array is an object.

True

True or False: Java allows you to use two different styles when declaring array reference variables. int[] numbers; or int numbers[];

True

True or False: Java does not limit the number of dimensions that an array may have. It is possible to create arrays with multiple dimensions, to model data that occurs in multiple set.

True

True or False: The enhanced for loops is designed to iterate once for every element in an array. Each time the loop iterates, it copies an array element to a variable.

True

LMAO THAT WAS THE ONLY QUESTION. WOW.

WOOOOOOW

which of the following variables are arrays? int[] a,b; int c, d[];

a,b,d

To add items to the ArrayList object, you use the ____method.

add (ArrayList.add(value);)

If x is a char, and values is an int array, then values[x]

casts x as an int based on x's ASCII value (for instance, if x is 'a' then it uses 97 and if x is 'z' then it uses 122)

if a and b are both int arrays, then a = b will

create an alias

As in the other members of the C family of languages (C, C++, C#), Java interprets a zero value as false and a non-zero value as true.

false

In Java, selection statements consist of the if and if-else statements.

false

In a two-dimensional array, both dimensions must have the same number of elements, as in[10][10]

false

It is possible to sort an array of int, float, double or String, but not an array of an Object class such as a CD class.

false

Just as arrays can only have a fixed number of elements, set at the time the array is declared, a parameter list also can only have a fixed number of elements, set at the time the method is declared

false

T/F: Arrays have a built in toString method that returns all of the elements in the array as one String with "\n" inserted between each element

false

To swap the 3rd and 4th elements in the int array values, you would do: values[3] = values[4]; values[4] = values[3];

false

To swap the 5rd and 6th elements in the int array values, you would do: temp =values[4]; values[5] = values[4]; values[4] = temp;

false

When comparing any primitive type of variable, == should always be used to test to see if two values are equal.

false

in Java, the symbol "=" and the symbol "==" are used synonymously (interchangeably).

false

The ArrayList class's ______ method returns the item stored at a specific index.

get(ArrayList.get(1);)

Each array in Java has a public field named ___________. This field contains the number of elements in the array.

length

A Java main method uses the parameter (String[ ] variable) so that a user can run the program and supply "command-line" parameters. Since the parameter is a String array, however, the user does not have to supply any parameters.

true

If the following statement is performed: CD[ ] mycollection = new CD[200]; where CD is a previously defined class, then mycollection[5] is a CD object.

true

The "off-by-one" error associated with arrays arises because the first array index is 0 and programmers may start at index 1, or may use a loop that goes one index too far

true

The following loop would adequately add 1 to each element stored in values。 for (j=0; j<values.length; j++) values[j]++;

true

The statement if (a >= b) a++; else b--; will do the same thing as the statement if (a < b) b--; else a++;.

true

The statement { } is a legal block.

true

In Java, arrays are

objects

The ArrayList class has a ______ method that removes an item at a specific index.

remove (ArrayList.remove(1);)

The ArrayList class's ______ method can be used to replace an item at a specific index with another item.

set (ArrayList.set(1, new value);)

The ArrayList class has a _____ method that reports the number of items stored in an ArrayList.

size (ArrayList.size();)

the "off-by-one" error associated with arrays arises because

the first array index is 0 and programmers may start at index 1, or may use a loop that goes one index too far

an array index cannot be a float, double, boolean, or String

true


Conjuntos de estudio relacionados

M04 Midterm Exam Part 1 ARTH 102

View Set

CCNA 2 v7 chapter 8 SLACC and DHCPv6

View Set

PHYC101 BSU Question Set 7 Bryan

View Set

GO! All in One Computer Concepts & Applications Final Ch 5-8

View Set

NSG 170 MASTER FINAL COMBINATION

View Set

Chapter 22: Nursing Management of the Postpartum Woman at Risk (Chapter Worksheet)

View Set