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, 22.06.2019 10:40
Nims is applicable to all stakeholders with incident related responsibilities. true or false
Answers: 1
question
Computers and Technology, 23.06.2019 16:00
What is the biggest difference between section breaks and regular page breaks? section breaks are more difficult to add than page breaks. section breaks make it easier for you to view the document as an outline. section breaks allow you to have areas of the document with different formatting. section breaks are smaller than regular page breaks.
Answers: 2
question
Computers and Technology, 23.06.2019 17:00
1. which of the following is not an example of an objective question? a. multiple choice. b. essay. c. true/false. d. matching 2. why is it important to recognize the key word in the essay question? a. it will provide the answer to the essay. b. it will show you a friend's answer. c. it will provide you time to look for the answer. d. it will guide you on which kind of answer is required.
Answers: 1
question
Computers and Technology, 24.06.2019 06:00
Hey i really need some solving this problem: 1. encrypt this binary string into cipher text: 110000. include in your answer the formula the decoder would use to decrypt your cipher text in the format (coded answer) x n mod (m) = y & 2. decrypt this cipher text into a binary string: 106 you.
Answers: 2
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
question
Mathematics, 10.02.2021 22:10
question
Mathematics, 10.02.2021 22:10
question
Mathematics, 10.02.2021 22:10
question
Health, 10.02.2021 22:10
Questions on the website: 13722362