compsci

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

Consider the following code segment. int i = a random number such that 1 <= i <= n; for (int a = 2; a <= i; a++)for (int b = 1; b < i; b++)System.out.println("*"); What is the minimum number of times that * will be printed? A 0 B 1 C 2 D n-1 E n-2

A 0

Consider the following code segment. public static void cvhs(int[ ] a, int y){if (a.length > 1)a[1] = a[1] * 2;y = y * 2;}What are the values of s and b after the code segment below has executed?Assume the following code segment is compiled without error. int[ ] s = {3,4};int b = 4;cvhs(s,b); A s={3, 8}; b=4; B s={3, 4}; b=4; C s={6, 4}; b=4; D s={3, 8}; b=8; E s={6, 8}; b=8;

A s={3, 8}; b=4;

Given: public boolean labTemp(int[ ] a, int val){boolean temp = false;for (int testVal : a) {if (testVal == val) {temp=true;}}return temp;} Which of the following best describes the conditions needed for temp to be true when it is returned? A Whenever the first element in a is equal to val B Whenever a contains any element which equals val C Whenever more than 1 element in a is equal to val D Whenever exactly 1 element in a is equal to val E Whenever the last element in a is equal to val

B Whenever a contains any element which equals val

Consider the following code segment:int p = 5;int q = 2;int sum = 0;while (p <= 8){sum += p % q;p++;q++;}What is the value of sum after the code is executed? A 1 B 0 C 7 D 13 E 4

C 7

Given the following code:String s1 = new String("bye");String s2 = new String("bye now");String s3 = s2.substring(0,3);String s4 = new String("bye"); Which of the following would return true?I. s1.equals(s3)II. s1 == s4III.s1.equals(s4) A III only B I only C II and III only D I and III only E II only

D I and III only

Which of the following code will produce the following output?1223334444I.for (int i = 1; i < 5; i++) {for (int j = i; j > 0; j--) {System.out.print(i+1);}System.out.println();} II.for (int i = 0; i < 5; i++) {for (int j = 0; j < i; j++) {System.out.print(i);}System.out.println();}III.for (int i = 1; i <= 5; i++) {for (int j = i; j > 0; j--) {System.out.print(i);}System.out.println();}IV.for (int i = 1; i < 6; i++) {for (int j = 0; j < i; j++) {System.out.println(i);}} A I and II B III only C I, II, and IV D IV only E II only

E II only

(a < b) && !(b > a) Assuming both integer variables (a and b) are declared and initialized without error, when will the expression above true? A a=b B a>b C b<a D Always true E Never true

E Never true


Conjuntos de estudio relacionados

prepU ch 42 Management of Patients With Musculoskeletal Trauma

View Set

Business Policy multi questions 3

View Set

Chapter 43: Assessment and Management of Patients with Hepatic Disorders

View Set

Preguntas sobre tiempo libre (10)

View Set