subject

An array is mirrored if one half of the array is a reflection of the other. For example, these are mirrored arrays: int[] a = {5, 4, 3, 4, 5};
int[] b = {9, 2, 2, 9};

The intent of the following methods is to determine whether an array is mirrored or not.

public boolean isMirrored(int[] array) {
// Add code here
}

private boolean isMirrored(int[] array, int leftIndex, int rightIndex) {
if (leftIndex > rightIndex) return true;
if (array[leftIndex] != array[rightIndex]) return false;
return isMirrored(array, leftIndex + 1, rightIndex - 1);
}

Which of the following statements, when inserted at the comment, “Add code here”, would complete the first isMirrored() method, call the second isMirrored() method, and produce the correct results?
A. return isMirrored(array)
B. return isMirrored(array, 0, 0)
C. return isMirrored(array, 0, array. length - 1);
D. return isMirrored(array, array[leftIndex], array[rightIndex]);

Which of the following is a method of the File class that can return an array of Files in a directory?
A. listFiles()
B. files()
C. getFiles()
D. directory()

Consider the following code.

public static int fileMethod(File dir) {
File[] files = dir. listFiles();
if (files == null) return 0;

int count = 0;
for (File f : files) {
if (f. isFile()) count++;
else count += fileMethod(f);
}
return count;
}

If dir represents a starting directory, which of the following statements best describes the operation of fileMethod()?
A. It counts and returns the number of files and directories inside dir and all subdirectories of dir.
B. It counts and returns the number of files, not counting directories, inside dir and all subdirectories of dir.
C. It counts and returns the number of files and directories only inside dir and inside only the first subdirectory found inside dir.
D. It counts and returns the number of files, not counting directories, but only those found inside dir and not its subdirectories.

Which of the following methods will correctly calculate the factorial of a positive number using iteration?
A.
public static long factorial(int n) {
if (n == 0) return 1;
else return n * factorial(n);
}
B.
public static long factorial(int n) {
if (n == 0) return 1;
else return n * factorial(n - 1);
}
C.
public static long factorial(int n) {
int product = n;
while (n > 0) {
n--;
product *= n;
}
return product;
}
D.
public static long factorial(int n) {
int product = n;
while (n > 1) {
n--;
product *= n;
}
return product;
}

Consider the following code.

public static String display(String s, int c) {
if (c == 0) return s;
else {
if (c > 3) return "-" + display(s, c - 1) + "-";
else return "=" + display(s, c - 1) + "=";
}
}

Which of the following methods most accurately reproduces the behavior of the display() method without using recursion?
A.
public static String d1(String s, int c) {
String retVal = "";
for (int i = 0; i < c; i++) {
if (i > 3) retVal += "-" + s + "-";
else retVal += "=" + s + "=";
}
return retVal;
}
B.
public static String d2(String s, int c) {
String retVal = "";
for (int i = 0; i < c - 3; i++) {
retVal += "-";
}
for (int i = 0; i < Math. min(3,c); i++) {
retVal += "=";
}
retVal += s;
for (int i = 0; i < Math. min(3,c); i++) {
retVal += "=";
}
for (int i = 0; i < c - 3; i++) {
retVal += "-";
}
return retVal;
}
C.
public static String d3(String s, int c) {
String retVal = "";
for (int j = 0; j < c - 3; j++) {
retVal += "-";
}
for (int j = 0; j < 3; j++) {
retVal += "=" + s + "=";
}
for (int j = 0; j < c - 3; j++) {
retVal += "-";
}
return retVal;
}
D.
public static String d4(String s, int c) {
String retVal = "";
for (int i = 0; i < c; i++) {
for (int j = 0; j < c - 3; j++) {
retVal += "-";
}
retVal += "===" + s + "===";
for (int j = 0; j < c - 3; j++) {
retVal += "-";
}
}
return retVal;
}

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 15:30
Brian wants to conduct an online search with a certain phrase. he intends to use the words books that belong to the 1800s in his search. how should he use the word that in his search?
Answers: 1
question
Computers and Technology, 25.06.2019 04:40
Ineed ! i need a computer whiz to me complete my study guide on computers, it's 50 questions. if anyone can me i'll be greatly appreciated.
Answers: 1
question
Computers and Technology, 25.06.2019 05:00
Brad wants to buy flowers for his friend with 33 dollars.the daisies are 1 dollar each and the roses are 2 dollars each he buy 3 more daisies than roses how much did the roses cost
Answers: 2
question
Computers and Technology, 25.06.2019 05:00
Craig keeps missing important staff meetings and getting double-booked for appointments. craig should use scheduling software a database diagramming software a word processor
Answers: 1
You know the right answer?
An array is mirrored if one half of the array is a reflection of the other. For example, these are m...
Questions