Suppose objects a and b are from a user-defined class that implements the Comparable interface. What must be true about the return value of a.compareTo(b) for the compareTo method that this class implements?
Blog
When writing a method, which of the following statements abo…
When writing a method, which of the following statements about exception handling is true?
Which sort algorithm starts by partitioning the array and se…
Which sort algorithm starts by partitioning the array and selecting a pivot element?
Consider the permutations method from the textbook, which is…
Consider the permutations method from the textbook, which is intended to return all permutations of the word passed in as a parameter. Which line contains the recursive call in the permutations method? public static ArrayList permutations(String word) { ArrayList result = new ArrayList(); if (word.length() == 0) // line #1 { result.add(word); // line #2 return result; // line #3 } else { for (int i = 0; i < word.length(); i++) // line #4 { String shorter = word.substring(0, i) + word(substring(i + 1); // line #5 ArrayList shorterPermutations = permutations(shorter); // line #6 for (String s : shorterPermutations) // line #7 { result.add(word.charAt(i) + s); // line #8 } } return result; // line #9 } }
Which data structure would best be used for keeping track of…
Which data structure would best be used for keeping track of groceries to be purchased at the food market?
The partial linear search method below is designed to search…
The partial linear search method below is designed to search an array of String objects. Select the expression that would be needed to complete the method. public static int search(String[] a, String item) { for(int i = 0; i < a.length; i++) { if ( ____________________________ ) { return i; } return -1; } }
Which data structure would best be used for keeping track of…
Which data structure would best be used for keeping track of groceries to be purchased at the food market?
Consider the permutations method from the textbook, which is…
Consider the permutations method from the textbook, which is intended to return all permutations of the word passed in as a parameter. Which line contains the recursive call in the permutations method? public static ArrayList permutations(String word) { ArrayList result = new ArrayList(); if (word.length() == 0) // line #1 { result.add(word); // line #2 return result; // line #3 } else { for (int i = 0; i < word.length(); i++) // line #4 { String shorter = word.substring(0, i) + word(substring(i + 1); // line #5 ArrayList shorterPermutations = permutations(shorter); // line #6 for (String s : shorterPermutations) // line #7 { result.add(word.charAt(i) + s); // line #8 } } return result; // line #9 } }
Select an appropriate expression to complete the following m…
Select an appropriate expression to complete the following method, which is designed to visit the elements in theList and replace each occurrence of the string “hello” with the string “goodbye”. public static void helloGoodbye(LinkedList theList) { ListIterator iterator = theList.listIterator(); while (iterator.hasNext()) { if (iterator.next().equals(“hello”)) { _____________________________ } } }
With a few exceptions, what access should instance variables…
With a few exceptions, what access should instance variables of classes always have?