Data Structures and Algorithms in Java
6th Edition
ISBN: 9781118771334
Author: Michael T. Goodrich
Publisher: WILEY
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 5, Problem 17C
Write a short recursive Java method that takes a character string s and outputs its reverse. For example, the reverse of 'pots&pans' would be 'snap&stop'.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a short recursive Java method that determines if a string s is a palindrome, that is, it is equal to its reverse. Examples of palindromes include 'racecar' and 'mom'. Test the method by asking the user to provide string entries to be checked. Hint: Check the equality of the first and last characters and recur (but be careful to return the correct value for both odd and even-length strings).
Write a static recursive method in Java called mRecursion that displays all of the permutations of the charactersin a string passed to the method as its argument. For example, the character sequence abc has thefollowing permutations: acb, bac, bca, cab, cba.
Then Write a static method called getInput that get aninput string from the user and passed it to the mRecursion method written above in a method call.Please does so using what I already had
//Get input from in to call recursive method //to display those char permutations public static String getInput ( ) { Scanner in = new Scanner(System.in); String combination = in.nextLine(); System.out.println("Enter string:);
return stringComb;
//Method to show permutations of a desired string// This only return 3 string combination for some reason static void myRecursion(String aString) { //isEmpty check if ( aString.length() == 0){…
Write a recursive method called reverseString() that takes in a string as a parameter and returns the string in reversed order. The main method is provided to read a string from the user and call the reverseString() method.
Use Java.
Ex: If the input of the program is:
Hello
the reverseString() method returns and the program outputs:
Reverse of "Hello" is "olleH".
Ex: If the input of the program is:
Hello, world!
the reverseString() method returns and the program outputs:
Reverse of "Hello, world!" is "!dlrow ,olleH".
Hint: Move the first character to the end of the returning string and pass the remaining sub-string to the next reverseString() method call.
import java.util.Scanner;
public class LabProgram {
/* TODO: Write recursive reverseString() method here. */public static void main(String[] args) {Scanner scnr = new Scanner(System.in);String input, result;input = scnr.nextLine();result = reverseString(input); System.out.printf("Reverse of \"%s\" is \"%s\".", input, result);}}
Chapter 5 Solutions
Data Structures and Algorithms in Java
Ch. 5 - Prob. 1RCh. 5 - Prob. 2RCh. 5 - Prob. 3RCh. 5 - Prob. 4RCh. 5 - Prob. 5RCh. 5 - Draw the recursion trace for the execution of...Ch. 5 - Prob. 7RCh. 5 - Describe a recursive algorithm for converting a...Ch. 5 - Prob. 9RCh. 5 - Prob. 10R
Ch. 5 - Prob. 11CCh. 5 - Prob. 12CCh. 5 - Give a recursive algorithm to compute the product...Ch. 5 - In Section 5.2 we prove by induction that the...Ch. 5 - Write a recursive method that will output all the...Ch. 5 - In the Towers of Hanoi puzzle, we are given a...Ch. 5 - Write a short recursive Java method that takes a...Ch. 5 - Write a short recursive Java method that...Ch. 5 - Use recursion to write a Java method for...Ch. 5 - Write a short recursive Java method that...Ch. 5 - Prob. 21CCh. 5 - Prob. 22CCh. 5 - Prob. 23CCh. 5 - Isabel has an interesting way of summing up the...Ch. 5 - Prob. 25CCh. 5 - Prob. 26CCh. 5 - Prob. 27PCh. 5 - Write a program for solving summation puzzles by...Ch. 5 - Prob. 29PCh. 5 - Write a program that can solve instances of the...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
True or False: When passing an argument to a method, the arguments data type must be compatible with the parame...
Starting Out with Java: Early Objects (6th Edition)
The trailing else in an if / else if statement has a similar purpose as the ________ section of a switch statem...
Starting Out with C++: Early Objects
Compare and contrast the break and continue statements.
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Explain the term foreign key, and give an example.
Database Concepts (8th Edition)
It has been suggested that the control software for a radiation therapy machine, used to treat patients with ca...
Software Engineering (10th 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 static recursive method evenFactors that takes as input two positive integers and prints the even factors of the first integer that are greater than or equal to the second integer. For example, evenFactors(18,1) prints 2, 6, and 18, since the even factors of 18 that are greater than or equal to 1 are 2,6, and 18.arrow_forwardWrite a Non tail recursion and a tail recursion method in Java with a test class that does the following: The factorial of a positive integer n —which we denote as n!—is the product of n and the factorial of n 1. The factorial of 0 is 1. Write two different recursive methods in Java that each return the factorial of n. Please and Thank youarrow_forwardjava-matlabarrow_forward
- Write a java program that uses a recursive method/algorithm to compute all permutations of a string that is unique taken from the user. Permutation is defined as a way or several possibilities in which a number or things can be organized. For example:arrow_forwardWrite a recursive function in Java that accepts an integer as input and returns 1 + 1/2 + 3 + 1/4 + ...(n or 1/n). The answer is the sum of the odd integers from 1 to n plus the sum of the reciprocals of the even integers.arrow_forwardjava code and outputarrow_forward
- Write a recursive method toNumber that forms the integer sum of all digit characters in a string. For example, the result of toNumber("3ac4") would be 7. [Hint: If next is a digit character ('0' through '9'), Character.isDigit(next) is true and the numeric value of next is Character.digit(next, 10)].arrow_forwardJAVA 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_forwardI need help coding this in java language.arrow_forward
- 4. A palindrome is a word that has the same spelling forwards and backwards, like "MADAM". Write a recursive Java method to check if a string is a palindrome.arrow_forwardWrite a program that has a main() function that calls a recursive method repeatPrint(String s, .....) that prints out the strings as shown in the example below: repeat Print ("CHICAGO", ....); C CH CHI CHIC CHICA CHICAG CHICAGO CHICAGO HICAGO ICAGO CAGO AGO GO 0arrow_forwardWrite a recursive method in java public static long numPaths(int r, int c) which can solve the following scenario: a checker is placed on a checkerboard. What are the fewest moves to get to the upper left corner(0,0)? You can only move sideways or vertically. No diagonal moves. Once you have that calculation, how many different ways are there to get to the upper left corner? this is my code but I am getting stock overflow, I'm not reaching my base case. public static long numPaths(int r, int c) { //base case if (r==0 && c==0 || r==0 || c==0) return 1; else { return numPaths(r, c--) + numPaths(r--, c); } }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