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 02:00
What is the process in which the software development team compiles information to determine the final product.
Answers: 3
question
Computers and Technology, 23.06.2019 15:10
What role did women fill during world war ii?
Answers: 1
question
Computers and Technology, 23.06.2019 17:30
Per the municipal solid waste report, what are the most common sources of waste (trash
Answers: 3
question
Computers and Technology, 24.06.2019 09:50
Create a string list. 2. use console.readline() to collect values of firstname, lastname, street, city, state, zip, save them to list. 3. write a simple linq statement, call method uppercasewords() to change first letter to uppercase. 4. create a foreach statment to display the information. public static string uppercasewords(string value) { char[] array = value.tochararray(); if (array.length > = 1) { if (char.islower(array[0])) { array[0] = char.toupper(array[0]); } } for (int i = 1; i < array.length; i++) { if (array[i - 1] == ' ') { if (char.islower(array[i])) { array[i] = char.toupper(array[i]); } } } return new string(array);
Answers: 3
You know the right answer?
Consider the following code. public void printNumbers(int x, int y) {
if (x < 5) {
S...
Questions
question
English, 28.01.2020 23:49
question
Chemistry, 28.01.2020 23:50
question
Mathematics, 28.01.2020 23:50
question
Biology, 28.01.2020 23:50
Questions on the website: 13722367