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 20C
Write a short recursive Java method that rearranges an array of integer values so that all the even values appear before all the odd values.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Java:
Write a recursive method that finds and returns the sum of the elements of an int array. Also, write a program to test your method.
Write 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.
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.
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
A file that contains a Flash animation uses the __________ file extension. a. .class b. .swf c. .mp3 d. .flash
Web Development and Design Foundations with HTML5 (8th Edition)
What is the disadvantage of having too many features in a language?
Concepts Of Programming Languages
Compare and contrast the break and continue statements.
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Write a statement or statements that can be used in a Java program to display the following on the screen: Java...
Java: An Introduction to Problem Solving and Programming (8th Edition)
A Game of 21 For this assignment, you will write a program that lets the user play against the computer in a va...
Starting Out with C++ from Control Structures to Objects (9th Edition)
Why is the study of database technology important?
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
- write a code in java (using recursion)arrow_forwardJAVA 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 code in java (using recursion)arrow_forward
- Write a recursive method that gets three parameters as input: an array of integers called nums, an integer called index,and an integer called The purpose of this method is to return true if value is stored in the array starting at nums[index]. That is, you have to check if value is equal to nums[index] or nums[index +1] or nums[index +2 ] …. nums[nums.length -1]. Do not use loops.(java code)arrow_forwardDo not use static variables to implement recursive methods. USING JAVA: // P6 public static int countSubstrings(String s1, String s2) { } Write a recursive method countSubstrings that counts the number of non-overlapping occurrences of a string s2 in a string s1. Use the method indexOf() from String class. As an example, with s1=”abab” and s2=”ab”, countSubstrings returns 2. With s1=”aaabbaa” and s2=”aa”, countSubstrings returns 2. With s1=”aabbaa” and s2=”AA”, countSubStrings returns 0. Show the output on the following strings: s1 = “Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities. Java applications are typically compiled to bytecode (class file) that can run on any Java Virtual Machine (JVM) regardless of computer architecture.…arrow_forwardSolve in javaFXarrow_forward
- Create a Java class RecursiveMethods.java and create the following methods inside: ALL THE METHODS NEED TO BE COMPLETED RECURSIVLY. NO LOOPS ALLOWED. - oddEvenMatchRec: the method takes an integer array as a parameter and returns a boolean. The method returns true if every odd index contains an odd integer AND every even index contains an even integer(0 is even). Otherwise it returns false. - sumNRec: The method takes an integer array A and returns the sum of all integers in the parameter array. - nDownToOne: Takes an integer n and prints out the numbers from n down to 1, each number on its own line. - inputAndPrintReverse: Inputs integers from the user until the user enters 0, then prints the integers in reverse order. For this method, you may NOT use an array or any type of array structure, in other words, you may not use any structure to store the user input.arrow_forwardwrite a code in java (using recursion)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_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