Consider the following code snippet. File inputFile = new File(“dataIn.txt”); Scanner in = new Scanner(inputFile); while (in.hasNext()) { String input = in.next(); } Which of the following statements about this code is correct?
Blog
The method checkArray examines an array arr: public static…
The method checkArray examines an array arr: public static boolean checkArray(int[] arr) { if (arr[0] >= arr[arr.length -1]) { return true; } return false; } What can you conclude about the running time of this section of code?
Consider the following code snippet. File inputFile = new F…
Consider the following code snippet. File inputFile = new File(“dataIn.txt”); Scanner in = new Scanner(inputFile); while (in.hasNext()) { String input = in.next(); } Which of the following statements about this code is correct?
If a class has an abstract method, which of the following st…
If a class has an abstract method, which of the following statements is NOT true?
If a class has an abstract method, which of the following st…
If a class has an abstract method, which of the following statements is NOT true?
The method findLargest examines the elements of an array arr…
The method findLargest examines the elements of an array arr which contains non-negative values public static int findLargest(int[] arr) { int curLargest = -1; for (int i = 0; i < arr.length; i++) { if (arr[i] >= curLargest) { curLargest = arr[i]; } } return curLargest; } What can you conclude about the running time of this section of code?
Consider the method powerOfTwo shown below: public boolean…
Consider the method powerOfTwo shown below: public boolean powerOfTwo(int n) { if (n == 1) // line #1 { return true; } else if (n % 2 == 1) // line #2 { return false; } else { return powerOfTwo(n / 2); // line #3 } } What is the best interpretation of line #1?
If an element is present in an array of length n, how many e…
If an element is present in an array of length n, how many element visits, in the worst case, are necessary to find it using a linear search?
Consider the method below, which displays the characters fro…
Consider the method below, which displays the characters from a String in reverse order. Each character appears on a separate line. Select the statement that should be used to complete the method so that it performs a recursive method call correctly. public static void printReverse(String word) { if (word.length() > 0) { ___________________________ System.out.println(word.charAt(0)); } }
Which of the following classes have a user-editable area?
Which of the following classes have a user-editable area?