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 09:30
What are the steps involved in accepting all the changes in a document? arrange these in order click edit. click accept or reject. click changes. click accept all.
Answers: 1
question
Computers and Technology, 22.06.2019 11:30
Hassan is writing his master’s thesis, which is a thirty-page document. he received some feedback from his professor in the form of comments, but does not see where the comments are. what is the fastest way for hassan to find the feedback?
Answers: 3
question
Computers and Technology, 22.06.2019 18:40
Mariah was working on a multimedia presentation that included both video and audio files. the file was huge, and she wanted to send it to her coworker in another office. she needed to reduce the size of the file so that it could be transmitted faster. the utility she used to do this was
Answers: 2
question
Computers and Technology, 22.06.2019 22:50
Assume the existence of a bankaccount class. define a derived class, savingsaccount that contains two instance variables: the first a double, named interestrate, and the second an integer named interesttype. the value of the interesttype variable can be 1 for simple interest and 2 for compound interest. there is also a constructor that accepts two parameters: a double that is used to initialize the interestrate variable, and a string that you may assume will contain either "simple", or "compound", and which should be used to initialize the interesttype variable appropriately. there should also be a pair of functions getinterestrate and getinteresttype that return the values of the corresponding data members (as double and int respectively).
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
Questions on the website: 13722360