Which of the following classes implement the Comparable interface? I Date II Collections III String
Blog
A palindrome is a word or phrase that reads the same forward…
A palindrome is a word or phrase that reads the same forward or backward. Consider the methods palindrome and isPal shown below: public boolean palindrome(String string) { return isPal(string, 0, string.length() – 1); } private boolean isPal(String string, int left, int right) { if (left >= right) { return true; } else if (string.charAt(left) == string.charAt(right)) { return isPal(string, left + 1, right – 1); } else { return false; } } The method isPal as shown here would be considered to be a ____ method.
The merge sort algorithm presented in section 14.4, which so…
The merge sort algorithm presented in section 14.4, which sorts an array of integers in ascending order, uses the merge method which is partially shown below. Select the condition that would be needed to complete the method so that the elements are sorted in descending order. private static void merge(int[] first, int[] second, int[] a) { int iFirst = 0; int iSecond = 0; int j = 0; while (iFirst < first.length && iSecond < second.length) { if (_____________________________) { a[j] = first[iFirst]; iFirst++; } else { a[j] = second[iSecond]; iSecond++; } j++; } // rest of the method follows here }
Consider the following code snippet. public interface Measu…
Consider the following code snippet. public interface Measurable { double getMeasure(); } public class Coin implements Measurable { public Coin(double aValue, String aName) { … } public double getMeasure() { return value; } … } public class BankAccount implements Measurable { public BankAccount(double initBalance) { … } public void getMeasure() { return balance; } … } Which of the following statements is correct?
The code below will not compile successfully unless the argu…
The code below will not compile successfully unless the argument to the makeMenuItem method is final. Why not? public JMenuItem makeMenuItem(final String menuLabel) { JMenuItem mi = new JMenuItem(menuLabel); class MyMenuListener implements ActionListener { public void actionPerformed(ActionEvent e) { doSomethingElse(); System.out.println(menuLabel); } } mi.addActionListener(new MyMenuListener()); return mi; }
What is a class called that represents the most general enti…
What is a class called that represents the most general entity in an inheritance hierarchy?
Which of the sorts in the textbook are based on the strategy…
Which of the sorts in the textbook are based on the strategy of divide and conquer? I quicksort II mergesort III insertion sort
Consider the following code snippet: Scanner in = new Scanne…
Consider the following code snippet: Scanner in = new Scanner(. . .); int ageValue = in.nextInt(); If there is no integer number appearing next in the input, what will occur?
Insert the missing code in the following code fragment. This…
Insert the missing code in the following code fragment. This fragment is intended to read an input file named dataIn.txt. public static void main(String[] args) throws FileNotFoundException { String inputFileName = “dataIn.txt”; File inputFile = new File(inputFileName); Scanner in = _______________; . . . }
Insert the missing code in the following code fragment. This…
Insert the missing code in the following code fragment. This fragment is intended to read an input file named dataIn.txt. public static void main(String[] args) throws FileNotFoundException { String inputFileName = “dataIn.txt”; File inputFile = new File(inputFileName); Scanner in = _______________; . . . }