Final Exam Prep

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

What is the value of times displayed?public class Test {public static void main(String[] args) {Count myCount = new Count();int times = 0; for (int i=0; i<100; i++)increment(myCount, times); System.out.println("myCount.count = " + myCount.count);System.out.println("times = "+ times);} public static void increment(Count c, int times) {c.count++;times++;}} class Count {int count; Count(int c) {count = c;} Count() {count = 1;}}

0

Give the first seven terms in the sequence created by the following recursive function f() starting at n=0.int f(int n){if (n <= 1)return n ;elsereturn f(n-1) + 2*f(n-2);}

0 1 1 3 5 11 21 43

What is the printout of invoking xfunction(6)? public static int xfunction(int n) {if (n >= 1)return 1;elsereturn n + xfunction(n - 2);}

1

What is the return value for xMethod(4) after calling the following method? static int xMethod(int n) {if (n == 1)return 1;elsereturn n + xMethod(n - 1);}

10

What is the printout of invoking xfunction(6)? public static int xfunction(int n) {if (n <= 1)return 1;elsereturn n + xfunction(n - 2);}

13

How many times is the recursive moveDisks method invoked for 4 disks?

15

Int h(int n){if (n == 0)return 0;elsereturn h(n/10) + n%10;}What is the output for each function call(a) Function call h(736). Output:(b) Function call h(12345). Output:

16,15

Trace the recursive function f() and give the output for the specified function callsint f(int n){if (n < 1)return 0;elsereturn f(n/10) + 1;}What is the output for each function call: Function call f(37) Output: Function call f(1212) Output:

2, 4

Consider the following recursive method. public static int m(int value) { if (value >= 0) return 5 * m(value - 2); else return 1; }What value is returned when invoking m(5)?

25

What is the output of the following code? public class Test {public static void main(String[] args) {java.math.BigInteger x = new java.math.BigInteger("3");java.math.BigInteger y = new java.math.BigInteger("7");x.add(y);System.out.println(x);}}

3

What is the printout of invoking xfunction(1234)?public static void xfunction(int n) { if (n > 0) { System.out.print(n % 10 + " "); xfunction(n / 10); }}

4 3 2 1

Assume arr is an array of integers with the elements {30,15,30,17,5,15,8}. After using the following declarations and the for-loop, give the order of elements in the resulting linked stack lst. int [ ] sArr2={30,15,30,17, 5, 15, 8};int i=0;LinkedStack<Integer> lst=new LinkedStack<Integer>();int fr=sArr2[0];for(i = 1; i < 7; i++)if (fr < sArr2[i])lst.push(fr);elsefr=sArr2[i];

5,5,15,15

Analyze the following recursive method.public static long factorial(int n) {return n * factorial(n - 1);} How many times is the factorial method invoked for factorial(5)?

6

What is the output produced as this code executes? ArrayBndQueue<Integer> pq=new ArrayBndQueue<Integer>();x = 8; y = 20;pq.enqueue((6));pq.enqueue(x));pq.enqueue(y);System.out.println(pq.dequeue());y=(Integer)pq.dequeue();pq.enqueue(3*y);pq.enqueue(35);while (!pq.isEmpty()){System.out.println(pq.dequeue());}

6 20 24 35

Which of the following statements are true?

A PriorityQueue orders its elements according to their natural ordering using the Comparable interface if no Comparator is specified. A PriorityQueue orders its elements according to the Comparator if a Comparator is specified in the constructor.

Suppose A is an abstract class, B is a concrete subclass of A, and both A and B have a default constructor. Which of the following is correct?

A a = new B();D. B b = new B();

Analyze the following code. Number numberRef = new Integer(0);Double doubleRef = (Double)numberRef;.

A runtime class casting exception occurs, since numberRef is not an instance of Double.

A constructor can access ___________.

A static variable A public instance variable A private instance variable

What is displayed by the following code?System.out.print("A,B;C".replaceAll(",;", "#") + " ");System.out.println("A,B;C".replaceAll("[,;]", "#"));

A,B;C A#B#C

Fill in the code to complete the following method for checking whether a string is a palindrome. public static boolean isPalindrome(String s) {if (s.length() <= 1) // Base casereturn true;else if _____________________________return false;elsereturn isPalindrome(s.substring(1, s.length() - 1)); }

A. (s.charAt(0) != s.charAt(s.length() - 1)) // Base case

Show the output of the following codepublic class Test1 { public static void main(String[] args) { System.out.println(f2(2, 0)); } public static int f2(int n, int result) { if (n == 0) return 0; else return f2(n - 1, n + result); }}

A. 0

Suppose list1 is an ArrayList and list2 is a LinkedList. Both contains 1 million double values. Analyze the following code:A:for (int i = 0; i < list1.size(); i++) sum += list1.get(i);B:for (int i = 0; i < list2.size(); i++) sum += list2.get(i);

A. Code fragment A runs faster than code fragment B.

Analyze the following code: public class Test {public static void main(String args[]) {NClass nc = new NClass();nc.t = nc.t++;}} class NClass {int t;private NClass() {}}

A. The program has a compilation error because the NClass class has a private constructor.

Suppose list list1 is [1, 2, 5] and list list2 is [2, 3, 6]. After list1.addAll(list2), list1 is __________.

A. [1, 2, 2, 3, 5, 6]

What is the printout for the third statement in the main method?public class Foo {static int i = 0;static int j = 0; public static void main(String[] args) {int i = 2;int k = 3;{int j = 3;System.out.println("i + j is " + i + j);} k = i + j;System.out.println("k is " + k);System.out.println("j is " + j);}}

A. j is 0

Analyze the following code: Number[] numberArray = new Integer[2];numberArray[0] = new Double(1.5);

At runtime, new Integer[2] is assigned to numberArray. This makes each element of numberArray an Integer object. So you cannot assign a Double object to it.

Which of the following is correct to sort the elements in a list lst?

B. Collections.sort(lst)

Analyze the following code:import java.util.*;public class Test { public static void main(String[] args) { PriorityQueue<Integer> queue = new PriorityQueue<Integer>( Arrays.asList(60, 10, 50, 30, 40, 20)); while (!queue.isEmpty()) System.out.print(queue.poll() + " "); }}

B. The program displays 10 20 30 40 50 60

For an instance of Collection, you can obtain its iterator using ________________.

B. c.iterator()

All the concrete classes in the Java Collections Framework implement _____________.

B. the Serializable interfaces

What is the output of the following code?import java.util.*;public class Test { public static void main(String[] args) { List<String> list1 = new ArrayList<>(); list1.add("Atlanta"); list1.add("Macon"); list1.add("Savanna"); List<String> list2 = new ArrayList<>(); list2.add("Atlanta"); list2.add("Macon"); list2.add("Savanna"); List<String> list3 = new ArrayList<>(); list3.add("Macon"); list3.add("Savanna"); list3.add("Atlanta"); System.out.println(list1.equals(list2) + " " + list1.equals(list3)); }}

B. true false

Suppose ArrayList x contains three strings [Beijing, Singapore, Tokyo]. Which of the following methods will cause runtime errors?

B. x.set(3, "New York"); C. x.get(3) D. x.remove(3)

What is the output of running class Test? public class Test {public static void main(String[] args) {new Circle9();}} public abstract class GeometricObject {protected GeometricObject() {System.out.print("A");} protected GeometricObject(String color, boolean filled) {System.out.print("B");}} public class Circle9 extends GeometricObject {/** Default constructor */public Circle9() {this(1.0);System.out.print("C");} /** Construct circle with a specified radius */public Circle9(double radius) {this(radius, "white", false);System.out.print("D");} /** Construct a circle with specified radius, filled, and color */public Circle9(double radius, String color, boolean filled) {super(color, filled);System.out.print("E");}}

BEDC

What is the printout of the following code? List<String> list = new ArrayList<String>(); list.add("A"); list.add("B"); list.add("C"); list.add("D"); for (int i = 0; i < list.size(); i++) System.out.print(list.remove(i));

C. AC

Which of the following is incorrect?

C. The constructors in an abstract class are private.D. You may declare a final abstract class.E. An interface may contain constructors.

Analyze the following code.public class Test { public static void main(String[] args) { Number x = new Integer(3); System.out.println(x.intValue()); System.out.println(x.compareTo(new Integer(4))); }}

C. The program has a compile error because x does not have the compareTo method.

what is the output of the following code?import java.util.*;public class Test { public static void main(String[] args) { ArrayList<Student> list = new ArrayList<>(); list.add(new Student("Peter", 65)); list.add(new Student("Jill", 50)); list.add(new Student("Sarah", 34)); Collections.sort(list); System.out.print(list + " "); Collections.sort(list, new StudentComparator1()); System.out.println(list); } static class StudentComparator1 implements Comparator<Student> { public int compare(Student s1, Student s2) { return s1.name.compareTo(s2.name); } } static class Student implements Comparable<Student> { String name; int age; Student(String name, int age) { this.name = name; this.age = age; } public int compareTo(Student s) { return this.age - s.age; } public String toString() { return "[" + name + ", " + age + "]"; } }}

C. [[Sarah, 34], [Jill, 50], [Peter, 65]] [[Jill, 50], [Peter, 65], [Sarah, 34]]

Fill in the code to complete the following method for computing a Fibonacci number. public static long fib(long index) { if (index == 0) // Base case return 0; else if (index == 1) // Base case return 1; else // Reduction and recursive calls return __________________; }

C. fib(index - 1) + fib(index - 2) D. fib(index - 2) + fib(index - 1)

To create a set that consists of string elements "red", "green", and "blue" Use:

C. new HashSet<String>(Arrays.asList(new String[]{"red", "green", "blue"})) D. new LinkedHashSet<String>(Arrays.asList(new String[]{"red", "green", "blue"}))

Fill in the code to complete the following method for sorting a list. public static void sort(double[] list) {___________________________;} public static void sort(double[] list, int high) {if (high > 1) {// Find the largest number and its indexint indexOfMax = 0;double max = list[0];for (int i = 1; i <= high; i++) {if (list[i] > max) {max = list[i];indexOfMax = i;}} // Swap the largest with the last number in the listlist[indexOfMax] = list[high];list[high] = max; // Sort the remaining listsort(list, high - 1);}}

C. sort(list, list.length - 1)

Suppose a list contains {"red", "green", "red", "green"}. What is the list after the following code? String element = "red"; for (int i = 0; i < list.size(); i++) if (list.get(i).equals(element)) { list.remove(element); i--; }

C. {"green", "green"}

Suppose a list contains {"red", "green", "red", "green"}. What is the list after the following code? String element = "red"; for (int i = list.size() - 1; i >= 0; i--) if (list.get(i).equals(element)) list.remove(element);

C. {"green", "green"}

Which of the following statements are true?

Collections.shuffle(list, Random) randomly reorders the elements in the list with a specified Random object. Collections.shuffle(list) randomly reorders the elements in the list. If list1 and list2 are identical, the two lists may be different after invoking Collections.sort(list1) and Collections.sort(list2). If list1 and list2 are identical, the two lists are still identical after invoking Collections.sort(list1, new Random(3)) and Collections.sort(list2, new Random(3)) with the same Random object.

Which of the following is correct to sort the elements in a list lst?

Collections.sort(lst)

Analyze the following code:public class Test { public static void main(String[] args) { int[] x = {1, 2, 3, 4, 5}; xMethod(x, 5); } public static void xMethod(int[] x, int length) { System.out.print(" " + x[length - 1]); xMethod(x, length - 1); }}

D. The program displays 5 4 3 2 1 and then raises an ArrayIndexOutOfBoundsException.

The class in this chapter is defined as a subclass of java.lang.Number. Which of the following expressions is correct?

Double x=new Rational(4, 5).doubleValue(); Integer x1= new Rational(4,5).intValue();

Analyze the following recursive method. public static long factorial(int n) { return n * factorial(n - 1); }

E. The method runs infinitely and causes a StackOverflowError.

class C { public void print(){ System.out.println("I am C");}public void print1(){ System.out.println();}}class B extends C{ public void print1(){ System.out.println("I am B");} public void print(){ System.out.println();}}public class Test { public static void main(String[] args) { C c = new C(); B b = new B(); b.print1(); b.print(); c.print1(); c.print(); }}

I am B I am C

Which of the following statements are true?

If you compile an interface without errors, a .class file is created for the interface. If you compile an interface without errors, but with warnings, a .class file is created for the interface. If you compile a class without errors but with warnings, a .class file is created.

Give the actual output of the fololowing code: ArrayStack<Integer> stk=new ArrayStack<Integer>();int x = 3, y = 19;stk.push(new Integer(6));stk.push(new Integer(x));stk.push(new Integer(y));System.out.println(stk.top());// Output 1_________stk.pop();Integer z1=(Integer)stk.top();int z2=z1.intValue();z2 =z2 * 4;stk.pop();stk.push(new Integer(z2));stk.push(new Integer(35));while (!stk.isEmpty()){System.out.println(stk.top() + " "); // Output 2______stk.pop();}

Output 1: 19 Output 2: 19

Analyze the following code. public class Test {public static void main(String[] args) {int n = 2;xMethod(n);System.out.println("n is " + n);} void xMethod(int n) {n++;}}

The code has a compile error because xMethod is not declared static.

The GeometricObject and Circle classes are defined in this chapter. Analyze the following code. public class Test {public static void main(String[] args) {GeometricObject x = new Circle(3);GeometricObject y = (Circle)(x.clone());System.out.println(x);System.out.println(y);}}

The program has a compile error because the clone() method is protected in the Object class. If GeometricObject implements Cloneable and Circle overrides the clone() method, the clone() method will work fine to clone Circle objects. To enable a Circle object to be cloned, the Circle class has to override the clone() method and implement the java.lang.Cloneable interface. After you override the clone() method and make it public in the Circle class, the problem can compile and run just fine, but y is null if Circle does not implement the Cloneable interface.

Analyze the following code. public class Test {public static void main(String[] args) {java.util.Date x = new java.util.Date();java.util.Date y = x.clone();System.out.println(x = y);}}

The program has a compile error because the return type of the clone() method is java.lang.Object.

Analyze the following code. 1. import java.util.*;2. public class Test {3. public static void main(String[] args) {4. Calendar[] calendars = new Calendar[10];5. calendars[0] = new Calendar();6. calendars[1] = new GregorianCalendar();7. }8. }

The program has a compile error on Line 5 because java.util.Calendar is an abstract class.

The Rational class extends java.lang.Number and implements java.lang.Comparable. Analyze the following code. public class Test {public static void main(String[] args) {Number[] numbers = {new Rational(1, 2), new Integer(4), new Double(5.6)};java.util.Arrays.sort(numbers);}}

The program has a runtime error because the compareTo methods in Rational, Integer, and Double classes do not compare the value of one type with a value of another type.

Analyze the following code. 1. public class Test {2. public static void main(String[] args) {3. Fruit[] fruits = {new Fruit(2), new Fruit(3), new Fruit(1)};4. java.util.Arrays.sort(fruits);5. }6. } class Fruit {private double weight;public Fruit(double weight) {this.weight = weight;}}

The program has a runtime error on Line 4 because the Fruit class does not implement the java.lang.Comparable interface and the Fruit objects are not comparable.

Analyze the following code: public class Test1 {public Object max(Object o1, Object o2) {if ((Comparable)o1.compareTo(o2) >= 0) {return o1;}else {return o2;}}}

The program would compile if ((Comparable)o1.compareTo(o2) >= 0) is replaced by (((Comparable)o1).compareTo(o2) >= 0). The program has a compile error because o1 is an Object instance and it does not have the compareTo method.

Analyze the following code: import java.util.*; public class Test {public static void main(String[] args) {PriorityQueue<Integer> queue =new PriorityQueue<Integer>(Arrays.asList(60, 10, 50, 30, 40, 20));for (int i: queue)System.out.print(i + " ");}}

There is no guarantee that the program displays 10 20 30 40 50 60

Assume the declaration of array weekName.String weekName[ ] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};Assume that the a glassqueue q1 contains the elements of weekName and a array stack stk1 contains the elements of the same array weekName. GlassQueue<String> q1=new GlassQueue<String>();ArrayStack<String> stk1=new ArrayStack<String>();String weekName[ ] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};String strB = (String)stk1.top();String strA = (String)q1.peekFront();while(strA != strB){stk1.pop();q1.dequeue();strB=(String)stk1.top();strA=(String)q1.peekFront();}System.out.println("strA= " + strA); After executing the loop, strA contains the following day :

Wed

What is displayed by the following code?public static void main(String[] args) {String[] tokens = "Welcome to Java".split("o");for (int i = 0; i < tokens.length; i++) {System.out.print(tokens[i] + " ");}}

Welc me t Java

What is the printout of the following code? ArrayList<Integer> l4 = new ArrayList<Integer>();l4.add(0);l4.add(1);l4.add(2);l4.add(1, 4);l4.set(2, 30);

[0, 1, 4, 30] x [0, 1, 2, 4, 30] X [0, 4, 30, 2]

List myList1 = Arrays.asList(1,2,5);List myList2 = Arrays.asList(2,3,6);PriorityQueue<Integer> q1 =new PriorityQueue<Integer>(Arrays.asList(1,2,5)); PriorityQueue<Integer> q2 =new PriorityQueue<Integer>(Arrays.asList(2,3,6)); q1.add(q2.poll());q1.add(q2.poll());q1.add(q2.poll());for (int i: q1)System.out.print(i + " ");

[1, 2, 2, 3, 5, 6] X [1,2,5,2,3,6]

What is list after the following code is executed?ArrayList<Integer> list = new ArrayList<Integer>();list.add(1);list.add(2);list.add(3);list.add(4);list.add(5);list.remove(2);System.out.println(list);

[1, 2, 4, 5]

What is the printout of the following code?import java.util.*; public class Test {public static void main(String[] args) throws Exception {ArrayList<Integer> list = new ArrayList();list.add(1); list.add(2); list.add(1); list.add(3);remove(list, 1);System.out.println(list);}public static void remove(ArrayList list, int value) {int k = 0;while (k < list.size()) {if (list.get(k).equals(value))list.remove(k);k++;}}}

[2, 3]

The printout from the following code is __________. java.util.ArrayList<String> list = new java.util.ArrayList<String>();list.add("New York");java.util.ArrayList<String> list1 = (java.util.ArrayList<String>)(list.clone());list.add("Atlanta");list1.add("Dallas");System.out.println(list1);

[New York, Dallas]

What is the infix expression corresponding to the postfix expression a a * b c + / d e - *

a2 /(b+c) * (d - e)

Which of the following class definitions defines a legal abstract class?

abstract class A { abstract void unfinished(); }

Assume the 5 element array bounded queue abq1 contains the characters in the string "train". What is content of abq1 after executing the instructions?ArrayUnbndQueue<Character> abq1=new ArrayUnbndQueue<Character>();char [ ] arr={'t', 'r', 'a', 'i', 'n'};abq1.dequeue();abq1.dequeue();abq1.enqueue('t');

aint

Show the output of running the class Test in the following code lines: interface A {} class C {} class B extends D implements A {} public class Test {public static void main(String[] args) {B b = new B();if (b instanceof A)System.out.println("b is an instance of A");if (b instanceof C)System.out.println("b is an instance of C");}} class D extends C {}

b is an instance of A followed by b is an instance of C.

Assume Calendar calendar = new GregorianCalendar(). __________ returns the week of the year.

calendar.get(Calendar.WEEK_OF_YEAR)

Assume: Calendar calendar = new GregorianCalendar(); __________ returns the number of days in a month.

calendar.getActualMaximum(Calendar.DAY_OF_MONTH);

Trace the recursive function and give the output for the specified function callsvoid f(char ch){if (ch >= 'a') && (ch <= 'h'){System.out.print(ch);++ch;f(ch);}elseSystem.out.println();}What is the output for: f('d')

defgh

What is displayed by the following code?System.out.print("Hi, ABC, good".matches("ABC ") + " ");System.out.println("Hi, ABC, good".matches(".*ABC.*"));

false true

void f(char ch){if ((ch >= 'a') && (ch <= 'h')){++ch;f(ch);System.out.print(ch);}elseSystem.out.println();} What is the ouput of f('d'):

ihgfe

Assume that a string expression contains the following "{(a+b)*(c+d)}". We want to store the expression in a stack. Write the code of a function you will call: void print_rec_rev_str(Stack str) which will print the reverse of the above expression: })d+c(*)b+a)}

import java.util.*;class Main {public static void main(String[] args) {//Declare expressionString expression = "{(a+b)*(c+d)}"; // create stack objectStack st = new Stack(); //push expression to stackfor(int i=0;i<expression.length();i++){st.push(expression.charAt(i));} //call print_rec_rev_str functionprint_rec_rev_str(st);System.out.println();} static void print_rec_rev_str(Stack str){ // while stack is not emptywhile(!str.empty()){ //print top elementSystem.out.print(str.peek()); //pop top element from stackstr.pop();}}}

What is the best suitable relationship between Employee and Faculty?

inheritance

What is a recursive function of the following non recursive function:int f (int n) {return n;} Make sure the function compiles and runs to receive perfect score

int f(int n) { if (n == 0) return 0; else return 1 + f(n-1); }

Which of the following is a correct interface?

interface A { void print();}

public static boolean isPalindrome(String s) {return isPalindrome(s, 0, s.length() - 1);} public static boolean isPalindrome(String s, int low, int high) {if (high <= low) // Base casereturn true;else if (s.charAt(low) != s.charAt(high)) // Base casereturn false;elsereturn _______________________________;}

isPalindrome(s, low + 1, high - 1)

What is the printout for the second statement in the main method?public class Foo {static int i = 0;static int j = 0; public static void main(String[] args) {int i = 2;int k = 3;{int j = 3;System.out.println("i + j is " + i + j);} k = i + j;System.out.println("k is " + k);System.out.println("j is " + j);}}

k is 2

Suppose list1 is ["Atlanta", "Macon"] and list2 is ["Atlanta", "Macon", "Savannah"], which of the following returns true?

list2.contains(list1.get(0));

Fill in the expression so that f1(3)=6: public class Test {public static void main(String[] args) {System.out.println(f1(3));} public static int f1(int n) {if (n == 0)return 0;else {return ---------; }}

n + f1(n - 1);

The Rational class in this chapter is defined as a subclass of java.lang.Number. Which of the following expressions is correct?

new Rational(5, 4).doubleValue();E. new Rational(5, 4).intValue();

When you create an ArrayList using: ArrayList<String> x = new ArrayList<String>(2), ________

no elements are currently in the array list. the array list capacity is currently 2.

The __________ method in the Queue interface retrieves and removes the head of this queue, or null if this queue is empty.

poll()

Which of the following declares an abstract method in an abstract Java class?

public abstract void method();

Fill in the code to complete the following method for binary search.public static int recursiveBinarySearch(int[] list, int key) { int low = 0; int high = list.length - 1; return __________________________;}public static int recursiveBinarySearch(int[] list, int key, int low, int high) { if (low > high) // The list has been exhausted without a match return -low - 1; // Return -insertion point - 1 int mid = (low + high) / 2; if (key < list[mid]) return recursiveBinarySearch(list, key, low, mid - 1); else if (key == list[mid]) return mid; else return recursiveBinarySearch(list, key, mid + 1, high);}

recursiveBinarySearch(list, key, low, high)

Fill in the code to complete the fibonacci function: public static int f(int i) {if (i == 0 || i == 1) // Base case________________else // Reduction casereturn f(i - 1) + f(i - 2);}

return i

What is the output of the following code? public class Test {public static void main(String[] args) {String s1 = new String("Welcome to Java!");String s2 = s1.toUpperCase(); if (s1 == s2)System.out.println("s1 and s2 reference to the same String object");else if (s1.equals(s2))System.out.println("s1 and s2 have the same contents");elseSystem.out.println("s1 and s2 have different contents");}}

s1 and s2 have different contents

What is the output of the following code? public class Test {public static void main(String[] args) {String s1 = new String("Welcome to Java!");String s2 = new String("Welcome to Java!"); if (s1 == s2)System.out.println("s1 and s2 reference to the same String object");elseSystem.out.println("s1 and s2 reference to different String objects");}}

s1 and s2 reference to different String objects

What is the output of the following code? public class Test {public static void main(String[] args) {String s1 = "Welcome to Java!";String s2 = s1; if (s1 == s2)System.out.println("s1 and s2 reference to the same String object");elseSystem.out.println("s1 and s2 reference to different String objects");}}

s1 and s2 reference to the same String object

Consider the linked unbounded queue:LinkedUnbndQueue s, t;Assume we have an array of elements arr2 as follows:int [ ] arr2= {48, 7, 15, 26, 4, 31, 10, 12}. Give the exact contents of lists s and t after the call to the method sList. You need to specify the content of s and t in order to receive full credit. sList(s, t);public static void sList(LinkedUnbndQueue one, LinkedUnbndQueue two){int j=1;int [ ] arr2= {48, 7, 15, 26, 4, 31, 10, 12};while (j != arr2.length){if (arr2[j]%2 == 1)one.enqueue(arr2[j]);elsetwo.enqueue(arr2[j]);++j;}}}

s= {7,15,31} t={48, 26, 4, 10, 12}

Assume StringBuilder strBuf is "ABCCEFC", after invoking _________, strBuf contains "ABTTEFT".

strBuf.replace(2, 7, "TTEFT");

Analyze the following code: public class Test {private int t; public static void main(String[] args) {int x;System.out.println(t);}}

t is non-static and it cannot be referenced in a static context in the main method.

After executing the following statements, what is the content of the unbounded array queue abq2?int [ ] arr3={'t','a','m','x'};ArrayUnbndQueue<Character> abq2=new ArrayUnbndQueue<Character>();abq2.enqueue('t');abq2.enqueue('a');int k=2;int c1=arr3[k];abq2.enqueue((char)++c1);abq2.enqueue((char)++arr3[++k]);

tany

Which of the following can be placed in the blank line in the following code?public class Test { private static int id; public void m1() { _____.id = 45; }}

test

What code may be filled in the blank without causing syntax errors: public class Test {java.util.Date date; public static void main(String[] args) {Test test = new Test();System.out.println(_________________);}}

test.date, date

A recursive method can always be converted into a nonrecursive method using iterations.

true

Given the declaration Circle[] x = new Circle[10], which of the following statement is most accurate?

x contains a reference to an array and each element in the array can hold a reference to a Circle object.


Set pelajaran terkait

chapter 11 study guide- Human Gen.

View Set

Chapter 4 Activity based Job Costing

View Set

5B troubleshooting Windows Network

View Set

AAMA Anatomy and Physiology Practice Exam

View Set

Prep U: Chpt. 30 Management of Patients with Hematologic Neoplasms

View Set

prep u Chapter 18: CNS Stimulants

View Set