Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 11, Problem 5E
Complete a recursive definition of the following method:
/**
Precondition: n >= 0.
Returns 10 to the power n.
*/
public static int computeTenToThe (int n)
Use the following facts about xn:
xn = (xn/2)2 when n is even and positive
xn = x(x(n–1)/2)2 when n is odd and positive
x0 = 1
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
how can i solve this using java?
Consider the following recursive method:
Public static int Fib(int a1, int a2, int n){ if(n == 1) return a1; else if (n == 2) return a2;else return Fib(a1, a2, n-1) + Fib(a1, a2, n-2);}
Please draw the recursion trace for Fib(2,3,5)
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…
Chapter 11 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Ch. 11.1 - What output will be produced by the following...Ch. 11.1 - What is the output produced by the following code?Ch. 11.1 - Write a recursive definition for the following...Ch. 11.1 - What is the output of the following code? public...Ch. 11.1 - Prob. 5STQCh. 11.1 - Complete the definition of the following method....Ch. 11.2 - Revise the method getCount in Listing 11.5 so that...Ch. 11.2 - Prob. 8STQCh. 11.2 - Prob. 9STQCh. 11.2 - Suppose you want me class ArraySearcher to work...
Ch. 11.2 - What Java statement will sort the following array,...Ch. 11.2 - How would you change the class MergeSort so that...Ch. 11.2 - How would you change the class MergeSort so that...Ch. 11.2 - If a value in an array of base type int occurs...Ch. 11.3 - Convert the following event handler to use the...Ch. 11 - What output will be produced by the following...Ch. 11 - What output will be produced by the following...Ch. 11 - Write a recursive method that will compute the...Ch. 11 - Write a recursive method that will compute the sum...Ch. 11 - Complete a recursive definition of the following...Ch. 11 - Write a recursive method that will compute the sum...Ch. 11 - Write a recursive method that will find and return...Ch. 11 - Prob. 8ECh. 11 - Write a recursive method that will compute...Ch. 11 - Suppose we want to compute the amount of money in...Ch. 11 - Prob. 11ECh. 11 - Write a recursive method that will count the...Ch. 11 - Write a recursive method that will remove all the...Ch. 11 - Write a recursive method that will duplicate each...Ch. 11 - Write a recursive method that will reverse the...Ch. 11 - Write a static recursive method that returns the...Ch. 11 - Write a static recursive method that returns the...Ch. 11 - One of the most common examples of recursion is an...Ch. 11 - A common example of a recursive formula is one to...Ch. 11 - A palindrome is a string that reads the same...Ch. 11 - A geometric progression is defined as the product...Ch. 11 - The Fibonacci sequence occurs frequently in nature...Ch. 11 - Prob. 4PPCh. 11 - Once upon a time in a kingdom far away, the king...Ch. 11 - There are n people in a room, where n is an...Ch. 11 - Prob. 7PPCh. 11 - Prob. 10PPCh. 11 - Prob. 12PP
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Assume that both of the inputs in the following circuit are 1. Describe what would happen if the upper input we...
Computer Science: An Overview (12th Edition)
Describe the three types of anomalies that can arise in a table and the negative consequences of each.
Modern Database Management
3.12 (Date Create a class called Date that includes three pieces Of information as data
members—a month (type ...
C++ How to Program (10th Edition)
Define each of the following terms: supertype subtype specialization entity cluster completeness constraint enh...
Modern Database Management (12th Edition)
What is the output of this loop? Identify the connection between the value of n and the value of the variable l...
Problem Solving with C++ (9th Edition)
Write an SQL statement to display the name, breed, and type for all pets that are not of type Cat, Dog, or Fish...
Database Concepts (8th 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
- java Write a recursive method largestDigitthat accepts an integer parameter and returns the largest digit value that appears in that integer. Your method should work for both positive and negative numbers. If a number contains only a single digit, that digit's value is by definition the largest. The following table shows several example calls: Call Value Returned largestDigit(14263203) 6 largestDigit(845) 8 largestDigit(52649) 9 largestDigit(3) 3 largestDigit(0) 0 largestDigit(-573026) 7 largestDigit(-2) 2 Obey the following restrictions in your solution: You may not use a String, Scanner, array, or any data structure (list, stack, map, etc.). Your method must be recursive and not use any loops (for, while, etc.). Your solution should run in no worse than O(N) time, where N is the number of digits in the number.arrow_forwardJAVA 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…arrow_forwardWrite a recursive method that takes two integers n and m as parameters, where m is one digit number. The method should output odd digits in n that are greater then m. For example: If n =374, m=5, the method should output 7 If n =5239, m=2, the method should output 9 3 5 The method prototype: public static void printDigits(int n, int m)arrow_forward
- The nth harmonic number is defined non-recursively as H(n) = 1+1/2+1/3+1/4+⋯+1/n Come up with a recursive definition and use it to guide you to write a method definition for a double-valued method named “harmonic” that accepts an int parameter n and recursively calculates and returns the nth harmonic number. Write a test program that displays the harmonic numbers, H(n), for n = 1,2,3,⋯,10.arrow_forwardSolve in javaFXarrow_forwardThe nth harmonic number is defined non-recursively as: H(n)=1+1/2+1/3+1/4+...+1/n Come up with a recursive definition and use it to guide you to write a method definition for a double-valued method named “harmonic” that accepts an int parameter n and recursively calculates and returns the nth harmonic number. Write a test program that displays the harmonic numbers, H(n)=1,2,3,4...10arrow_forward
- The following recursive method get Number Equal searches the array x of 'n integers for occurrences of the integer val. It returns the number of integers in x that are equal to val. For example, if x contains the 9 integers 1, 2, 4, 4, 5, 6, 7, 8, and 9, then getNumberEqual(x, 9, 4) returns the value 2 because 4 occurs twice in x. public static int getNumberEqual(int x[], int n, int val) { if (n< 0) ( return 0; } else { if (x[n-1) == val) { return getNumberEqual(x, n-1, val) +1; } else { return getNumber Equal(x, n-1, val); } // end if ) // end if } // end get Number Equal Demonstrate that this method is recursive by listing the criteria of a recursive solution and stating how the method meets each criterion.arrow_forwardjava codearrow_forwardIn Java Ackermann’s Function Ackermann’s function is a recursive mathematical algorithm that can be used to test how well a computer performs recursion. Write a method ackermann(m, n), which solves Ackermann’s function. Use the following logic in your method: If m = 0 then return n + 1 If n = 0 then return ackermann(m - 1, 1) Otherwise, return ackermann(m - 1, ackermann(m, n - 1)) Test your method in a program that displays the return values of the following method calls: ackermann(0, 0) ackermann(0, 1) ackermann(1, 1) ackermann(1, 2)ackermann(1, 3) ackermann(2, 2) ackermann(3, 2)arrow_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_forward1. Let product(n,m) be a recursive addition-subtraction method for multiplying two positive integers. Recursive cases for m = 1 and m < 1 make this method. The return value should be n plus a recursive product() call with n and m - 1. Test a Java method.arrow_forwardWrite a recursive method that returns thelargest integer in an array. Write a test program that prompts the user to enter alist of eight integers and displays the largest element.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
Introduction to Big O Notation and Time Complexity (Data Structures & Algorithms #7); Author: CS Dojo;https://www.youtube.com/watch?v=D6xkbGLQesk;License: Standard YouTube License, CC-BY