Consider the following code snippet: LinkedList myLList = ne…

Consider the following code snippet: LinkedList myLList = new LinkedList(); myLList.add(“Mary”); myLList.add(“John”); myLList.add(“Sue”); ListIterator iterator = myLList.listIterator(); iterator.next(); iterator.next(); iterator.add(“Robert”); iterator.previous(); iterator.previous(); iterator.remove(); System.out.println(myLList); What will be printed when this code is executed?

The method below generates all nonempty substrings of a word…

The method below generates all nonempty substrings of a word passed as argument.   Assuming that the string contains no duplicate characters, select the statement to complete the method so that it prints all nonempty substrings correctly. public static void printSubstrings(String word) { if (word.length() > 0) { for (int j = 1; j

Consider the following code snippet: public interface Measur…

Consider the following code snippet: public interface Measurable { double getMeasure(); ____________ double sum(Measurable[] objects) { // implementation to compute the sum of the Measurable objects } } Which of the following completes the interface declaration correctly?

Consider the sort method shown below for selection sort: pub…

Consider the sort method shown below for selection sort: public static void sort(int[] a) { for (int i = 0; i < a.length – 1; i++) { int minPos = minimumPosition(i); swap(minPos, i); } } Suppose we modify the loop condition to read i < a.length. What would be the result?

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) __________________ { String inputFileName = “dataIn.txt”; File inputFile = new File(inputFileName); Scanner in = new Scanner(inputFile); . . . }

Consider the Counter class below. public class Counter { p…

Consider the Counter class below. public class Counter { public int count = 0; public int getCount() { return count; } public void increment() { count++; } } Using the class above and the variables declared below, what is the value of num1.equals(num2)? Counter num1 = new Counter(); Counter num2 = num1;

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) __________________ { String inputFileName = “dataIn.txt”; File inputFile = new File(inputFileName); Scanner in = new Scanner(inputFile); . . . }

Consider the method below, which prints the digits of an arb…

Consider the method below, which prints the digits of an arbitrary positive integer in reverse order, one digit per line.  The method should print the last digit first. Then, it should recursively print the integer obtained by removing the last digit. Select the statements that should be used to complete the method. public static void printReverse(int value) { if (value > 0) { _____________________ // print last digit _____________________ // recursive call to print value without last digit } }