What will be displayed by the method call recurse

Assignment Help JAVA Programming
Reference no: EM131119541

Java Quiz

Question 1

Method A invokes method A itself. This is called _________.

indirect recursion
explicit recursion
direct recursion
one-step recursion

Question 2

What are the base cases in the following recursive method?

public static void recurse(int n)
{
if (n > 0)
{
System.out.print(n % 10);
recurse(n / 10);
}
}

n < 0
n <= 0
n > 0
no base cases

Question 3

What will be displayed by the method call recurse(1234)?

public static void recurse(int n)
{
if (n <= 0)
{
System.out.print(n % 10);
recurse(n / 10);
}
}

1234
4 3 2 1
Nothing
4321

Question 4

Analyze the following recursive method and indicate which of the following will be true.

public static long factorial(int n)
{
return n * factorial(n - 1);
}

Invoking factorial(2) returns 2.
Invoking factorial(1) returns 1.
The method runs infinitely and causes a StackOverflowError.
Invoking factorial(0) returns 0.

Question 5

Fill in the code to complete the following method for computing factorial.

// Return the factorial for a specified index
public static long factorial(int n)
{
if (n == 0)
return 1;
else
return _____________;
}

n * (n - 1)
n
n * factorial(n - 1)
factorial(n - 1) * (n - 1)

Question 6

What will be displayed by the method call recurse(6)?

public static intrecurse(int n)
{
if (n <= 1)
return 1;
else
return n + recurse(n - 2);
}

13
14
11
12

Question 7

The base case _________ the recursion.

stops
breaks
pauses
starts

Question 8

What is the output of the following program?

{
public static void main(String[] args)
{
System.out.println(countDown(2, 0));
}
public static intcountDown(int n, int result)
{
if (n == 0)
return 0;
else
return countDown(n - 1, n + result);
}
}

1
3
0
2

Question 9

Which of the following statements about recursive methods is accurate?

They must have exactly 1 base case and exactly 1 recursive case
They must have at least 1 base case and at least 1 recursive case
They must have exactly 1 base case and at least 1 recursive case
They must have at least 1 base case and exactly 1 recursive case

Question 10

Which of the following is a possible disadvantage of recursion?

Recursive solutions can be less efficient than their iterative counterparts
Recursive solutions tend to have more local variables than their iterative counterparts
Recursive solutions tend to be longer than their iterative counterparts
Recursive solutions are more likely to go into infinite loops than their iterative counterparts

Question 11

To declare an interface named A with two generic types, use

public interface A(E) { ... }
public interface A<E, F> { ... }
public interface A<E> { ... }
public interface A(E, F) { ... }

Question 12

Will the following code have a runtime error?
Comparable date = new Date();
inti = date.compareTo("time");

Always
Never
Only when date contains an invalid date
Only when date is not the current date

Question 13

To create a list to store integers, use

ArrayList<Object> list = new ArrayList<Integer>();
ArrayList<Number> list = new ArrayList<Integer>();
ArrayList<int> list = new ArrayList();
ArrayList<Integer> list = new ArrayList();

Question 14

To create a generic type bounded by Number, use

<E extends Object>
<E extends Number>
<E>
<E extends Integer>

Question 15

Which of the following describes the benefit of using generic classes to implement collections?

It eliminates the need to downcast objects when they are removed from a collection
It eliminates the need to upcast objects when they are inserted into a collection
It eliminates the need to downcast objects when they are inserted into a collection
It eliminates the need to upcast objects when they are removed from a collection

Question 16

Suppose list list1 is [1, 2, 5] and list list2 is [2, 3, 6]. After list1.addAll(list2), list2 is __________.

[1, 5]
[1, 2, 3, 5, 6]
[2, 3, 6]
[1, 2, 2, 3, 5, 6]

Question 17

Suppose a list contains {red, red, red, red}. What is the list after the following code?

String element = "red";
for (inti = list.size() - 1; i>= 0; i--)
if (list.get(i).equals(element))
list.remove(element);

[red]
[red, red]
[]
[red, red, red]

Question 18

Which of the following is correct to sort the elements in a list aList?

Arrays.sort(aList)
new LinkedList<String>(new String[]{red, green, blue})
Collections.sort(aList)
aList.sort()

Question 19

Which of the following best describes all objects of type List?

They define an ordered collection that prohibits duplicates
They define an ordered collection that allows duplicates
They define an unordered collection that allows duplicates
They define an unordered collection that prohibits duplicates

Question 20

Which of the following problems would be a good candidate for using a stack?

A print spooler that dispatches jobs based on shortest job first
An inventory system that processes product records by product number
A program that is designed to evaluate expressions
A task scheduler that schedules tasks in the order that they are received.

Reference no: EM131119541

Questions Cloud

Documentation of sources : Format: The paper should follow APA style, in both the overall format of the paper and in the documentation of sources. It should be double-spaced, with 1" margins.
Explaining the needs of special offenders : How do special needs, mentally ill, and substance-abusing prisoners affect the jail and prison systems at state and federal levels  - What would happen if these prisoners were not cared for properly?
Identify the location and timeframe of a project : Consider as many financial constraints and gains that would be effected by the water park. What kinds of avenues for providing public input and dialogue about a publicly funded water park project. Additional evidence, research, comparisons, and fi..
How can you reconcile a bankruptcy declaration : In 2001, Polaroid Corporation declared bankruptcy. How can you reconcile a bankruptcy declaration with a management pledged to maximize shareholder wealth?
What will be displayed by the method call recurse : What will be displayed by the method call recurse(1234)? Which of the following problems would be a good candidate for using a stack? Which of the following is correct to sort the elements in a list aList?
The worker cannot move adequately around : Assume a worker is so obese that the worker cannot move adequately around your work place, so you want to fire the worker. The worker is not protected by Title VII. Describe another act and a theory under which the worker might be protected.
Idea with strengths and weaknesses : The steps are stated in our text. McCarthy, E. J., Perreault, W. D., & McCarthy, J. P. (2014) stated: "(1) Idea generation which includes ideas from customers and users, marketing research, competitors, and other markets. (2) The screening process..
What is the expected cost of the promotion : Grear Tire Company has produced a new tire with an estimated mean lifetime mileage of 36,500 miles. Management also believes that the standard deviation is 5000 miles and that tire mileage is normally distributed. For each tire sold, what is the expe..
Identify the strategy and methods to achieve the goal : The assignment is to read the following three scenarios. Using the concepts and skills learned in class, students will have to identify the strategy and methods to achieve the goal of the scenario.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Create a program in java that displays hello world

Create a program in Java that displays "Hello world!", No Design Section is required for this assignment, Copy and Paste your code into the Source Programs section and a screen shot of the results in the Output section.

  Java program that will add the corresponding elements

Develop a Java program that will add the corresponding elements of two 1-dimensional arrays X and Y to produce the 1-dimensional array Z. Arrays X, Y, Z have the same dimension [M].

  Write a java method that adds two fractions together

Write a Java method that adds two fractions together

  What is value of returnvalue after given code has executed

What is the value of returnValue after the following code has been executed?x = "150";y = "100";returnValue= x - y; Which of the following uses correct syntax to receive a value stored in totalCost?

  Create a servlet to display a table

NetBeans for Java with GlassFish/Tomcat: https://netbeans.org/downloads/ (select All option)) and create a servlet to display a table that contains factorials for the numbers from 0 to 10, as shown

  Program to calculate semester grade based on the scores

Write a java application program that takes in user input from keyboard and calculate semester grade based on the scores. I need help, to rewrite the program, instead of taking keyboard input, you will use dialog box to prompt user, take input, an..

  The fileiohelper class provides 2 class methods

1.int FileIOHelper.getNumberofStudents(String fileName): takes a String parameter which is the name of an input file in the format described above, and returns the number of students in the file

  Achieving simplicity and merely being simplistic

What is the difference between achieving simplicity and merely being simplistic?

  Declares three arraylist objects referenced by the objects

Write a program called ThreeArrayLists.java that declares three ArrayList objects referenced by the objects named priceList, quantityList, and amountList

  Create a temperature sensor simulator

create a temperature sensor simulator. First, display a menu that will ask the user what season to simulate (1) winter (2) spring (3) summer (4) fall or (5) to exit. Once the use selects the season your program should ask the user how many simulation..

  Write a program that ask the user to enter a usemame

Write a program usennuftevalidator.java that ask the user to enter a usemame and checks whether the usemame meets the following criteria

  How to setup a program to respond to events

Discussing how to setup a program to respond to events from any one of these sources - How do you create the necessary listener class? How do you associate the listener object with the event source?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd