Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

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 { ... }
public interface A { ... }
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 list = new ArrayList();
ArrayList list = new ArrayList();
ArrayList list = new ArrayList();
ArrayList list = new ArrayList();

Question 14

To create a generic type bounded by Number, use




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(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.

Java, Programming

  • Category:- Java
  • Reference No.:- M91877105
  • Price:- $20

Priced at Now at $20, Verified Solution

Have any Question?


Related Questions in Java

Project requirementsfor the problem described in the next

Project requirements For the problem described in the next section, you must do the following: 1. include your student ID at the end of all filenames for all java code files. Three classes have been identified in section ...

Assignment - method in our madnessthe emphasis for this

Assignment - "Method in our Madness" The emphasis for this assignment is methods with parameters. In preparation for this assignment, create a folder called Assign_3 for the DrJava projects for the assignment. A Cityscap ...

Answer the following question whats the difference public

Answer the following Question : What's the difference public inheritance and private inheritance? What can derived classes inherit from base classes? What cannot be inherited from base classes?

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

In ruby the hash class inherits from enumerable suggesting

In Ruby, the Hash class inherits from Enumerable, suggesting to a programmer that Hashes are collections. In Java, however, the Map classes are not part of the JCF (Java Collections Framework). For each language, provide ...

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

Simple order processing systemquestion given the classes

Simple Order Processing System Question: Given the classes Ship (with getter and setter), Speedboat, and SpeedboatTest. Answer the following questions: Refine the whole application (all classes) and create Abstract class ...

Chatbotscreate a small networked chat application that is

Chatbots Create a small, networked chat application that is populated by bots. Introduction On an old server park, filled with applications from the early days of the internet, a few servers still run one of the earliest ...

Operating systems assignment -problem 1 sharing the bridgea

Operating Systems Assignment - Problem 1: Sharing the Bridge A new single lane bridge is constructed to connect the North Island of New Zealand to the South Island of New Zealand. Farmers from each island use the bridge ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As