Consider the following code segment. int count = 5; while (count < 100) { count = count * 2; } count = count + 1; What will be the value of count as a result of executing the code segment?
Blog
Consider the following methods, which appear in the same cla…
Consider the following methods, which appear in the same class. public int function1(int i, int j) { return i + j; } public int function2(int i, int j) { return j – i; } Which of the following statements, if located in a method in the same class, will initialize the variable x to 11?
Consider the following code segment. int outerMax = 10; int…
Consider the following code segment. int outerMax = 10; int innerMax = 5; for (int outer = 0; outer < outerMax; outer++) { for (int inner = 0; inner
Consider the following code segment. int value = 15; while (…
Consider the following code segment. int value = 15; while (value < 28) { System.out.println(value); value++; } What are the first and last numbers output by the code segment?
Consider the following code segment. int num = 5; num *= 2;…
Consider the following code segment. int num = 5; num *= 2; num %= 6; What is the value of num after the code segment is executed?
Consider the following code segment. /* missing loop header…
Consider the following code segment. /* missing loop header */ { for (int k = 0; k < 4; k++) { System.out.print(k); } System.out.println(); } The code segment is intended to produce the following output. 0123 0123 0123 Which of the following can be used to replace /* missing loop header */ so that the code segment works as intended? for (int j = 0; j < 3; j++) for (int j = 1; j < 3; j++) for (int j = 1; j
Consider the following code segment. String str = “a black…
Consider the following code segment. String str = “a black cat sat on a table”; int counter = 0; for (int i = 0; i < str.length() - 1; i++) { if (str.substring(i, i + 1).equals("a") && !str.substring(i + 1, i + 2).equals("b")) { counter++; } } System.out.println(counter); What is printed as a result of executing this code segment?
Consider the following code segment. String dessert = “pie”…
Consider the following code segment. String dessert = “pie”; dessert += “straw” + dessert + “berry”; What is the value of dessert after the code segment has been executed?
Consider the following code segment. String str = “AP”; str…
Consider the following code segment. String str = “AP”; str += “CS ” + 1 + 2; System.out.println(str); What is printed as a result of executing the code segment?
Consider the following method definition. The method printAl…
Consider the following method definition. The method printAllCharacters is intended to print out every character in str, starting with the character at index 0. public static void printAllCharacters(String str) { for (int x = 0; x < str.length(); x++) // Line 3 { System.out.print(str.substring(x, x + 1)); } } The following statement is found in the same class as the printAllCharacters method. printAllCharacters("ABCDEFG"); Which choice best describes the difference, if any, in the behavior of this statement that will result from changing x < str.length() to x