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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 21:00, mazolethrin9632
Which of these is most responsible for differences between the twentieth century to the twenty-first century?
Answers: 2
image
Computers and Technology, 22.06.2019 23:30, Molly666
What does 21 pilots middle aged name as a band 15 years prior to them naming their band 21 pilots?
Answers: 1
image
Computers and Technology, 23.06.2019 00:30, vane3152
If joey was single and his taxable income was $9,500, how much would he pay in taxes each year?
Answers: 1
image
Computers and Technology, 24.06.2019 23:50, fish64
What is your fav video game currently: a) roblox b) fortnite c) apex legends d) pubg
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 in other subjects: