subject

Consider the following code. public void printNumbers(int x, int y) {
if (x < 5) {
System. out. println("x: " + x);
}
if (y > 5) {
System. out. println("y: " + y);
}
int a = (int)(Math. random() * 10);
int b = (int)(Math. random() * 10);
if (x != y) printNumbers(a, b);
}

Which of the following conditions will cause recursion to stop with certainty?
A. x < 5
B. x < 5 or y > 5
C. x != y
D. x == y

Consider the following code.

public static int recur3(int n) {
if (n == 0) return 0;
if (n == 1) return 1;
if (n == 2) return 2;
return recur3(n - 1) + recur3(n - 2) + recur3(n - 3);
}

What value would be returned if this method were called and passed a value of 5?
A. 3
B. 9
C. 11
D. 16

Which of the following methods correctly calculates the value of a number x raised to the power of n using recursion?
A.
public static int pow(int x, int n) {
if (x == 0) return 1;
return x * pow(x, n);
}
B.
public static int pow(int x, int n) {
if (x == 0) return 1;
return x * pow(x, n - 1);
}
C.
public static int pow(int x, int n) {
if (n == 0) return 1;
return x * pow(x, n);
}
D.
public static int pow(int x, int n) {
if (n == 0) return 1;
return x * pow(x, n - 1);
}

Which of the following methods correctly calculates and returns the sum of all the digits in an integer using recursion?
A.
public int addDigits(int a) {
if (a == 0) return 0;
return a % 10 + addDigits(a / 10);
}
B.
public int addDigits(int a) {
if (a == 0) return 0;
return a / 10 + addDigits(a % 10);
}
C.
public int addDigits(int a) {
return a % 10 + addDigits(a / 10);
}
D.
public int addDigits(int a) {
return a / 10 + addDigits(a % 10);}

The intent of the following method is to find and return the index of the first ‘x’ character in a string. If this character is not found, -1 is returned.

public int findX(String s) {
return findX(s, 0);
}

Which of the following methods would make the best recursive helper method for this task?
A.
private int findX(String s) {
if (index >= s. length()) return -1;
else if (s. charAt(index) == 'x') return index;
else return findX(s);
}
B.
private int findX(String s, int index) {
if (index >= s. length()) return -1;
else return s. charAt(index);
}
C.
private int findX(String s, int index) {
if (index >= s. length()) return -1;
else if (s. charAt(index) == 'x') return index;
else return findX(s, index);
}
D.
private int findX(String s, int index) {
if (index >= s. length()) return -1;
else if (s. charAt(index) == 'x') return index;
else return findX(s, index + 1);
}

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 03:10
This program reads a file called 'test.txt'. you are required to write two functions that build a wordlist out of all of the words found in the file and print all of the unique words found in the file. remove punctuations using 'string.punctuation' and 'strip()' before adding words to the wordlist. write a function build_wordlist() that takes a 'file pointer' as an argument and reads the contents, builds the wordlist after removing punctuations, and then returns the wordlist. another function find_unique() will take this wordlist as a parameter and return another wordlist comprising of all unique words found in the wordlist. example: contents of 'test.txt': test file another line in the test file output: ['another', 'file', 'in', 'line', 'test', 'the']
Answers: 1
question
Computers and Technology, 22.06.2019 15:30
Why would a programmer use the logical operator and in an if statement? a: when an action is to be taken that requires both conditions to be falseb: when an action is to be taken that requires both conditions to be truec: when an action is to be taken that requires the first condition to be falsed: when an action is to be taken that requires the second condition to be truei took the test and the answer is b.
Answers: 3
question
Computers and Technology, 23.06.2019 04:31
Acloud service provider uses the internet to deliver a computing environment for developing, running, and managing software applications. which cloud service model does the provider offer? a. iaas b. caas c. maas d. paas e. saas
Answers: 1
question
Computers and Technology, 23.06.2019 14:30
Which of the following would not be considered a pc? a. mainframe b. desktop c. tablet pc d. laptop
Answers: 2
You know the right answer?
Consider the following code. public void printNumbers(int x, int y) {
if (x < 5) {
S...
Questions
Questions on the website: 13722367