Java: An Introduction to Problem Solving and Programming (7th Edition)
7th Edition
ISBN: 9780133766264
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 11.1, Problem 3STQ
Write a recursive definition for the following method:
For example, the call displaySharps (3) is equivalent to
If you have trouble writing this method, simplify it so that the output does not advance to the next line. For that simpler case, you need not worry about the distinction between print and println. In the simpler case, you use only print. After doing the simpler case, try to do the exercise as stated.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
I need the answer as soon as possible
Create, compile, and run a recursive program. Choose one of the labs listed below and program it. More details for the
lab can be found in the first PowerPoint for Chapter 9. Make sure your code is recursive. You can think of recursive
code this way: If you cut and paste a recursive method into another class, it should still run without problems. In other
words, you cannot have any instance variables (class-level variables) that the method depends on.
Choice 1 - boolean isPalindrome (String str) that returns true if the input string is a palindrome.
Choice 2 - boolean find (string fullStr, string subStr) that tests whether the string subStr is a substring of fullStr
Choice 3- int numDigits (int num) to determine the number of digits in the number num
Choice 4 - double intPower (double x, int n) to compute x^n, where n is a positive integer and x is a double precision
variable
Choice 5-void printSubstr (String str) that prints all substrings of the input string.
Complete the java program. Use two methods and make one of them recursive
Chapter 11 Solutions
Java: An Introduction to Problem Solving and Programming (7th 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 - 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. 10PP
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Explain the use of the SQL transaction control language (TCL) statements BEGIN TRANSACTION, COMMIT TRANSACTION,...
Database Concepts (7th Edition)
Consider the following C program void fun (void) { int a, b, c; / defiinition.1 / . . . while (. . .) int b, c,...
Concepts of Programming Languages (11th 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)
Modify the temperature conversion program to print a heading above the table.
C Programming Language
Create an application that converts Celsius to Fahrenheit. The formula is F = 1.8 C + 32 where F is the Fahren...
Starting Out With Visual Basic (8th Edition)
Write a complete C++ program that writes the phrase Hello world to the screen. The program does nothing else.
Problem Solving with C++ (9th 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
- You have a card on which the letter J is written on one side and K on the other. You want to see all of the possible ways the card will land if you drop it n times. Write a recursive method that prints each session of dropping the cardswith J's and K's in java?arrow_forwardWrite a static recursive method that returns the number of digits in theinteger passed to it as an argument of type int. Allow for both positiveand negative arguments. For example, –120 has three digits. Do not countleading zeros. Embed the method in a program, and test it.arrow_forwardWrite a recursive solution to the problem below. You MUST use only one method, and that method must have the provided method header. You are allowed to use loops, but you must also use recursion. Given a word of length n, print every possible word of length n that can be made with those characters. Note: The order of the output does not matter, only that all possibilities are listed. Example: Input: rot Output: rot, rto, otr, ort, tro, tor Input: frog Output: frog, frgo, fogr, forg, fgro, fgor, rogf, rofg, rgfo, rgof, rfog, rfgo, ogfr, ogrf, ofrg, ofgr, orgf, orfg, gfro, gfor, grof, grfo, gofr, gorf public void printAllPossibilities (String prefix, String suffix){ }arrow_forward
- Write down only the methods that are required; testers are not requiredarrow_forwardMake a recursive method for factoring an integer n. First, find a factor f, then recursively factor n / f. This assignment needs a resource class and a driver class; these two classes will need to be in two separate files. The resource class will contain all of the methods and the driver class only needs to call the methods. The driver class needs to have only 5 lines of code. The code needs to be written in Java.arrow_forwardGiven a list of integers, you want to know whether it is possible to divide the integers into two sets, so that the sums of the two sets are the same. Every integer must be in one set or the other. Write a recursive helper method that takes any number of arguments you like, and make the initial call to your recursive helper method from equalSum(). Do not use any loops or regular expressions. Test case 1: equalSum([2, 3, 5]) true Test case 2: equalSum([2, 2, 5]) falsearrow_forward
- JAVA Phone numbers and PIN codes can be easier to remember when you find words that spell out thenumber on a standard phone pad. For example, instead of remembering the combination 5282,you can just think of JAVA.Write a recursive method that, given a number, yields all possible spellings (which may or maynot be real words).arrow_forwardWrite a Java program that asks the user to enter a string and counts how many times the letter "s" or "S" appears in the string. Display that number and then display the string that many times. Requirements: Call a method that gets the string from the user. Use recursion to ensure the string has at least 5 characters. Call a method that returns the number of times the letter "s" or "S" appears in the string. This method should use recursion. Call a method that takes the number of times the letter"s" or "S" appeared in the string and display the original string that was obtained from the user that many times using recursion. Call a method that sorts the letters in the string and searches for the letter "m". Display Found or Not Found.arrow_forwardWrite a recursive method that displaysa string reversely on the console using the following header: public static void reverseDisplay(String value) For example, reverseDisplay("abcd") displays dcba. Write a test programthat prompts the user to enter a string and displays its reversal.arrow_forward
- For this exercise, you will create several recursive functions in order to get a better understanding of how recursion works. In exercise 2, we will illustrate using recursion for creating art. Create a new project in IntelliJ called Recursion. Add a new Java class called Recursion with a public static main function. You will add several functions to your Recursion class as follows: 1 Write a recursive function int sum(int n) that adds up the numbers from n to 1 and print your result. For example from main do the following: Recursion recursion = new Recursion();System.out.println(recursion.sum(6)); 1.2 Write a recursive function factorial(int n) that calculates the factorial of n. Print out the results. Add your function to your Recursion class. 1.3. Write a recursive function powerOf10(int n) that calculates 10n. 1.4. Write a more general recursive function powerOfN(int x, int p) that calculates the power of xp. Do not use the Math.pow function. 1.5.…arrow_forwardHave a research on the use of the Math methods and write a program that uses Math method. Use at least 10 methods. Using recursion, write a program that tells whether a number is palindrome or not Write a Java program that determines whether a positive integer is a prime number. Use a method that reads positive integer, second method that returns true if the number is prime; otherwise returns false and a method that prints a message telling whether is a prime number or not. Sample Output: Positive Integer: 73 73 is a prime number Have a research on the use of the Date and Time methods and write a program that uses Date and Time method. Use at least 3. Have a research on the use of the String methods and write a program that uses String method. Use at least 10.arrow_forwardHow to write a recursive method called palindrome and a non-recursive method called palindromenonrecursive in java that determine if a string is a palidrome (ignore characters that are not letters). Then write a driver to test the two versions of the two methods. (A palindrome is a string that reads the same forward as well as backward. For example, “otto” and “never odd or even” are palindromes)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