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 06:30
You are consulting for a beverage distributor who is interested in determining the benefits it could achieve from implementing new information systems. what will you advise as the first step?
Answers: 1
question
Computers and Technology, 24.06.2019 01:00
What are two ways to access the options for scaling and page orientation? click the home tab, then click alignment, or click the file tab. click the file tab, then click print, or click the page layout tab. click the page layout tab, or click the review tab. click the review tab, or click the home tab?
Answers: 2
question
Computers and Technology, 24.06.2019 05:30
Someone plzz me which of these defines a social search? a. asking a search engine a question that is answered by a real person on the other sideb. modifying search results based on popularity of a web pagec.modifying search results based on a ranking of a web page
Answers: 2
question
Computers and Technology, 24.06.2019 15:30
What is the total number of time zones that can be configured to show by default in a calendar in outlook 2016?
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
Questions on the website: 13722359