Computer Science 1212 Test 2

Ace your homework & exams now with Quizwiz!

infinite

A loop that never ends is a _______ loop

for

A(n) ___ loop is appropriate for a definite number of iterations.

Pancake 3 Pancake 4 Pancake 5

What does this code output? int x = 2; while(x < 5) { System.out.println("Pancake " + (x + 1)); x++; }

6

What is the output of the code fragment given below? int i = 0; int j = 0; while (i < 12){ i = i + 2; j++;} System.out.println("j=" + j);

diddl

What is the value of str after the following code has been executed? String str; String sourceStr = "Hey diddle, diddle, the cat and the fiddle"; str = sourceStr.substring(12,17);

9

What is the value of y after the following sequence of statements? int y = 8; y++;

1, 2, 4, 8, 16, 32

What output is generated by this for loop? for (int i = 1; i <= 50; i = i * 2) System.out.println(i);

do

What type of loop is executed at least once?

j = j * 2;

j *= 2 an also be written as _____.

j--

Select the number below that should fill the blank in the for loop to give this output. 10 9 8 7 for( int j = 10; j >= 7; ______) System.out.print(j + " ");

j+=2

Select the number below that should fill the blank in the for loop to give this output. 2 4 6 8 10 for( int j = 2; j <= 10; ______) System.out.print(j + " ");

pre-test

The while loop is a _________________ loop?

W

Assuming that str is declared as follows, String str = "RSTUVWXYZ"; what value will be returned from str.charAt(5)?

i = 0

Fill in the blank to complete this common use of the for loop. for (int ______; i < str.length(); i++) { char ch = str.charAt(i); // Process ch }

charAt()

If I want to get the character of the first position of a string, what method do I use?

No, because the string is 15 letters long, you cannot reference the 15th slot without an exception

If a string named message has a length of 15, is message.charAt(15) a valid statement?

total is equal to 4

If total = 200 and amount =50, then after the the Java statement below, which of the following is true?:

indexOf()

If you want to get the position number of a character in a string, what method is used?

to declare a constant

In Java, the keyword *final is used

*final

In Java, what reserved word is used to identify constants?

a way to terminate

In all cases, with very few exceptions, loops must contain ___.

The first returns the substring starting from the 11th slot to the 19th slot, the second returns the substring starting from the 0th slot to the 10th slot

Whats the difference between message.substring(11) and message.substring(0, 11) assuming message has a string length of 20?

for

Which loop is preferred when a variable runs from a starting to an ending value with a constant increment or decrement?

while(num > 10 && num % 3 != 0)

Which of the following conditions allows the loop to keep iterating as long as the value of the variable num is greater than 10, but not divisible by 3?

do while

Which of the following is NOT a pretest loop?

do while

Which of the following is considered a post-test loop?

"UNCC".toLowerCase()

Which of the following is the correct statement to return uncc?

balance += amount;

Which of the following statements is equivalent to balance = balance + amount;?

double p = Math.pow(2,3);

Which statement correctly computes a specified number raised to the specified power?

Math.abs(x-y)

Which statement correctly computes the absolute value of the difference between x and y?

double s = Math.sqrt(16);

Which statement correctly computes the square root of the given number?


Related study sets

Situations: Humerus & Shoulder Girdle

View Set

upper GI disorders - week 4 day 1

View Set

Module 3 Planning and Building a Business

View Set

NHM 363 Final Exam (Modules 1-12)

View Set

Chapter 13: Abdominal Vasculature

View Set

Banking Products & Services Vocabulary

View Set