Starting Out with Java: Early Objects (6th Edition)
6th Edition
ISBN: 9780134462011
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 14, Problem 4MC
This is when a method explicitly calls itself.
- a. explicit recursion
- b. modal recursion
- c. direct recursion
- d. indirect recursion
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
JAVA
Question 2:
For two integers m and n, their GCD (Greatest Common Divisor) can be computed by a recursive method. Write a recursive method gcd(m,n) to find their Greatest Common Divisor.
Method body:
If m is 0, the method returns n. If n is 0, the method returns m. If neither is 0, the method can recursively calculate the Greatest Common Divisor with two smaller parameters: One is n, the second one is m mod n (or m % n). The recursive method cannot have loops.
Note: although there are other approaches to calculate Greatest Common Divisor, please follow the instructions in this question, otherwise you will not get the credit.
main method:
Prompt and read in two numbers to find the greatest common divisor.
Call the gcd method with the two numbers as its argument. Print the result to the monitor.
Example program run:
Enter m:
12
Enter n:
28
GCD(12,28) = 4
And here is what I have so far,
package CSCI1302;import java.util.*;public class RecursionDemo {
public static void…
Indirect recursion is when function A calls
function B, which in turn calls function A.
is it true or false.
solve q5 only please
Chapter 14 Solutions
Starting Out with Java: Early Objects (6th Edition)
Ch. 14.2 - It is said that a recursive algorithm has more...Ch. 14.2 - Prob. 14.2CPCh. 14.2 - What is a recursive case?Ch. 14.2 - What causes a recursive algorithm to stop calling...Ch. 14.2 - What is direct recursion? What is indirect...Ch. 14 - Prob. 1MCCh. 14 - This is the part of a problem that can be solved...Ch. 14 - This is the part of a problem that is solved with...Ch. 14 - This is when a method explicitly calls itself. a....Ch. 14 - Prob. 5MC
Ch. 14 - Prob. 6MCCh. 14 - True or False: An iterative algorithm will usually...Ch. 14 - True or False: Some problems can be solved through...Ch. 14 - True or False: It is not necessary to have a base...Ch. 14 - True or False: In the base case, a recursive...Ch. 14 - Find the error in the following program: public...Ch. 14 - Prob. 1AWCh. 14 - Prob. 2AWCh. 14 - What will the following program display? public...Ch. 14 - Prob. 4AWCh. 14 - What will the following program display? public...Ch. 14 - Convert the following iterative method to one that...Ch. 14 - Write an iterative version (using a loop instead...Ch. 14 - What is the difference between an iterative...Ch. 14 - What is a recursive algorithms base case? What is...Ch. 14 - What is the base case of each of the recursive...Ch. 14 - What type of recursive method do you think would...Ch. 14 - Which repetition approach is less efficient: a...Ch. 14 - When recursion is used to solve a problem, why...Ch. 14 - How is a problem usually reduced with a recursive...Ch. 14 - Prob. 1PCCh. 14 - isMember Method Write a recursive boolean method...Ch. 14 - String Reverser Write a recursive method that...Ch. 14 - maxElement Method Write a method named maxElement,...Ch. 14 - Palindrome Detector A palindrome is any word,...Ch. 14 - Character Counter Write a method that uses...Ch. 14 - Recursive Power Method Write a method that uses...Ch. 14 - Sum of Numbers Write a method that accepts an...Ch. 14 - Ackermarms Function Ackermanns function is a...Ch. 14 - Recursive Population Class In Programming...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Write a function whose prototype is char lastChar(const char str) that takes a nonempty C-string as parameter a...
Starting Out with C++: Early Objects
Rock, Paper, Scissors Game Write a program that lets the user play the game of Rock, Paper, Scissors against th...
Starting Out with Python (4th Edition)
The ____________ is always transparent.
Web Development and Design Foundations with HTML5 (8th Edition)
T F It is not necessary for each node in a linked list to have a self-referential pointer.
Starting Out with C++ from Control Structures to Objects (9th Edition)
How do you convert an integer into a string? How do you convert a numeric string into an integer? How do you co...
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- solve q6 only pleasearrow_forwardRecursive Power MethodWrite a method called powCal that uses recursion to raise a number to a power. The method should accept two arguments: The first argument is the exponent and the second argument is the number to be raised (example” powCal(10,2) means 210). Assume that the exponent is a nonnegative integer. Demonstrate the method in a program called Recursive (This means that you need to write a program that has at least two methods: main and powCal. The powCal method is where you implement the requirements above and the main method is where you make a method call to demonstrate how your powCal method work).arrow_forwardA recursive method with no base case? 1.causes an infinite loop 2.generates no output 3.does not start 4.all of the answersarrow_forward
- Using JAVA Recursive Power Method Write a method called powCalthat uses recursion to raise a number to a power. The method should accept two arguments: The first argument is the exponentand the second argument is the number to be raised(example”powCal(10,2)means2^10). Assume that the exponent is anonnegative integer. Demonstrate the method in a program called Recursive (This means that you need to write a program that has at least two methods: mainand powCal. The powCal method is where you implement the requirements above and the main method is where you make a method call to demonstrate how your powCalmethod work).arrow_forwardJava Program: Recursive Method There are n people in a room where n is an integer greater then or equal to 2. Each person shakes hands once with every other person. What is the total number of handshakes in the room? Write a recursive method to solve this problem with the following header:public static int handshake(int n)where handshake(n) returns the total number of handshakes for n people in the room. To get you started if there are only one or two people in the room, then:handshake(1)=0handshake(2)=1arrow_forwardExercise-3: Write a recursive and iterative methods to convert a decimal number to its binary equivalent string. The iterative algorithm (in pseudo-code) for converting a decimal integer into a binary integer as follows: 1. If the integer is 0 or 1, its binary equivalent is 0 or 1. 2. If the integer is greater than or equal to 2 do the following: 3. Divide the integer by 2. 4. Separate the result into a quotient and remainder. 5. Divide the quotient again and repeat the process until the quotient is zero. 6. Write down all remainders in reverse order as a string. 7. This string is the binary equivalent of the given integer. // Recursive decimal to binary method public static String dec2binRecursive(int n) { if (n<2) return n+ " ". else return dec2binRecursive(n/2) + n%2; } a) Write the Complete program for above Recursive decimal to binary method Algorit b) Iterative decimal to binary methodarrow_forward
- 1. Write a recursive method expFive(n) to compute y=5^n. For instance, if n is 0, y is 1. If n is 3, then y is 125. If n is 4, then y is 625. The recursive method cannot have loops. Then write a testing program to call the recursive method. If you run your program, the results should look like this: > run RecExpTest Enter a number: 3 125 >run RecExpTest Enter a number: 3125 2. For two integers m and n, their GCD(Greatest Common Divisor) can be computed by a recursive function. Write a recursive method gcd(m,n) to find their Greatest Common Divisor. Once m is 0, the function returns n. Once n is 0, the function returns m. If neither is 0, the function can recursively calculate the Greatest Common Divisor with two smaller parameters: One is n, the second one is m mod n. Although there are other approaches to calculate Greatest Common Divisor, please follow the instructions in this question, otherwise you will not get the credit. Meaning your code needs to follow the given algorithm. Then…arrow_forward3arrow_forwardI want solution with steparrow_forward
- Java language Write a recursive method to add all of the odd numbers between two numbers (start and end) and return the result. The method receives these numbers as parameters.arrow_forwardThe word ladder game was invented by Lewis Carroll in 1877. The idea is to begin with a start word and then change one letter at a time until you arrive at an end word. Each word along the way must be an English word. For example, starting from FISH, you can arrive at MAST through the following word ladder:FISH, WISH, WASH, MASH, MAST Write a program that uses recursion to find the word ladder given a start word and an end word, or that determines no word ladder exists. Use the file words.txt that is available online with the source code for the book as your dictionary of valid words. This file contains 87,314 words. Your program does not need to find the shortest word ladder between words; any word ladder will do if one exists. list aalii aardvark aardvarks aardwolf aba abaca abaci abacist aback abacus abacuses abaft abalone abalones abamp abampere abandon abandoned abandonee abandoner abandonersarrow_forwardWrite a recursive method that converts a decimal number intoa hex number as a string. The method header ispublic static String dec2Hex(int value)Write a test program that prompts the user to enter a decimal number and displaysits hex equivalent.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY