EXAM 1/WK 4 QUICK CHECK

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

3. initialization, condition, increment

Going from left to right, what are the three sections of a for loop header? 1. condition, initialization, increment 2. increment, initialization, condition 3. initialization, condition, increment 4. initialization, increment, condition 5. condition, increment, initialization 6. increment, condition, initialization

True

T/F: A String method can be called through a string literal.

False You can use the new operator, but often a string literal will suffice

T/F: A String object cannot be created using the new operator.

False That is a character set; a character encoding defines how characters are stored in memory

T/F: A character encoding is the list of all characters used by a programming language.

True

T/F: A constructor of a class has the same name as the class.

True

T/F: A for loop could always be written as an equivalent while loop.

True

T/F: A while loop affects a program's flow of control. True

True

T/F: After a method finishes executing, control returns to the place the method was called.

False An assignment statement does not determine which statement is executed text

T/F: An assignment statement affects a program's flow of control.

True

T/F: An if statement affects a program's flow of control. True

False They can be separate activities

T/F: An object must be created when its object reference variable is declared.

True

T/F: Attempting to follow a null reference will cause an exception to be thrown.

True

T/F: In some cases, a sentinel value can be used to signal the end of input.

False It's possible, but not likely

T/F: In the High-Low program, it's impossible for the user to guess the target value in one guess.

False It depends on how long it takes the user to guess the target value

T/F: In the High-Low program, the number of times the while loop will be executed can be calculated before the loop begins.

True

T/F: In the Palindromes program, a potential palindrome is evaluated by comparing characters at both ends and working inwards.

True

T/F: In the Palindromes program, the inner loop evaluates one string to see if it is a palindrome.

True

T/F: In the Palindromes program, the inner loop stops comparing characters if the string is determined not to be a palindrome.

True

T/F: Java uses the Unicode character set to represent characters.

True

T/F: The High-Low program would still work if the initial value of guess were set to -1 instead of -999.

False The keyword new is an operator, not a method

T/F: The Java keyword new is a method that can be called to create objects.

True

T/F: The Unicode character set represents over 65,000 characters.

False Like a while loop, if the condition is false initially, the body is never executed

T/F: The body of a for loop is always executed at least once.

True

T/F: The body of a while loop may never execute.

False It often is, but might also be declared previously

T/F: The control variable must be declared in the for loop header.

False Although its called the increment section, you can update the control variable in any way you'd like

T/F: The increment section of the for loop header always adds 1 to the loop control variable.

False The logic of the if statement could be written to check any of the possibilities in any order

T/F: The nested if statement in the High-Low program had to be written so that it checks for the correct guess last.

False Even though it's in all lower case letters, the spaces would throw it off

T/F: The string "i prefer pi" would be considered a palindrome by the original version of the Palindromes program.

False The program must be interrupted by pressing CTRL-C or CTRL-Break or by closing the run window

T/F: There is no way to stop an infinite loop.

True

T/F: Using a while loop to check each input value for correctness is a form of input validation.

if statement

Which of the following is NOT a repetition statement in Java? if statement while statement for statement for-each statement do-while statement They are all repetition statements.

1. It's a number that is the basis of the calculated pseudorandom numbers.

What is the role of the seed value of a random number generator? 1. It's a number that is the basis of the calculated pseudorandom numbers. 2. It's the maximum number of values that can be produced by the generator. 3. It's the maximum value that can be generated by that object. 4. It's the minimum value of any range produced by the generator.

Num: 3

What output is printed by the following code? String str = "Rephactor Java"; int index = 0; int num = 0; while (index < str.length()) { if (str.charAt(index) == 'a') num++; index++; } System.out.println("Num: " + num); Num: 0 Num: 3 Num: 10 Num: 14 No output because the code contains an infinite loop.

***** ***** ***** ***** *****

What output is produced by the following code? for (int i = 1; i <= 5; i++) { for (int j = 1; j <= 5; j++) System.out.print("*"); System.out.println(); } * ** *** **** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** * ** *** **** *****

4. lexicographic ordering

What technique is used to put Unicode characters and strings in order? 1. ASCII ordering 2. character encoded ordering 3. alphabetical ordering 4. lexicographic ordering

15

What value is printed by the following code? int count = 0; for (int i = 0; i < 5; i++) count += 3; System.out.println(count); 0 5 12 15 18

0 to 24

After the following line of code is executed, the value stored in the variable num will be in what range? num = (int) (Math.random() * 25); 0 to 24 1 to 24 0 to 25 1 to 25

5 to 14

If gen refers to a Random object, the expression gen.nextInt(10) + 5 will produce a value in what range? 5 to 14 5 to 10 0 to 15 10 to 15

-2 to 9

If gen refers to a Random object, the expression gen.nextInt(12) - 2 will produce a value in what range? -2 to 10 1 to 10 0 to 10 -2 to 9

0 to 29

If gen refers to a Random object, the expression gen.nextInt(30) will produce a value in what range? 0 to 30 1 to 30 1 to 29 0 to 29

2. gen.nextInt(10) + 1

If gen refers to a Random object, which of the following expressions would produce a value in the range 1 to 10? 1. gen.nextInt(11) + 1 2. gen.nextInt(10) + 1 3. gen.nextInt(1) + 10 4. gen.nextInt(1) + 11

3. A loop condition that is never false.

What causes an infinite loop? 1. A loop body that is never executed. 2. A loop control variable that is repeatedly modified. 3. A loop condition that is never false. 4. A loop condition that is always false.

4. Prints the multiples of 3 between 3 and 30 (3, 6, 9, etc.)

What does the following for loop do? for (int num = 3; num <= 30; num += 3) System.out.println(num); 1. Prints the numbers from 3 to 30 (3, 4, 5, etc.) 2. Prints the sum of the numbers from 3 to 30. 3. Prints the sum of the multiples of 3 between 3 and 30. 4. Prints the multiples of 3 between 3 and 30 (3, 6, 9, etc.)

2. A subset of Unicode containing primarily English characters and basic symbols.

What is ASCII? 1. A technique for ordering Unicode characters. 2. A subset of Unicode containing primarily English characters and basic symbols. 3. A technique for representing Unicode characters in memory. 4. A set of non-printable Unicode characters. None of the above.

4. The order in which statements are executed.

What is a program's flow of control? 1. The order in which interface events are processed. 2. The order in which loop bodies are executed. 3. The order in which methods are called. 4. The order in which statements are executed.

4. linear

What is the default flow of control through a method? 1. repetitious 2. conditional 3. binary 4. linear


Set pelajaran terkait

Chapter 50: Assessment and Management of Patients With Biliary Disorders

View Set

Diagnostic Test AP World History

View Set

Final Exam Questions — Post Review (1)

View Set

Pathophysiology : Kidney Lecture

View Set

Reproduction, Clotting Unit 3 Semester 4

View Set