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 3E
Write a recursive method that will compute the number of odd digits in a number.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
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).
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.
Write a recursive method that takes two integer number start and end. The method int evensquare2
(int start, int end) should return the square of even number from the start number to the end number.
Then, write the main method to test the recursive method. For example:
If start = 2 and end = 4, the method calculates and returns the value of: 22 * 4= 20
If start = 1 and end 2, the method calculates and returns the value of: 22 4
Sample I/O:
Enter Number start: 2
Enter Number start: 4
Result = 20
Enter Number start: 1
Enter Number start: 2
Result = 4
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
What must a computer have in order for it to execute Java programs?
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
This statement causes a function to end and sends a value back to the part of the program that called the funct...
Starting Out with Python (3rd Edition)
In Exercises 3 through 24, carry out the task.
Create a button containing the word “PUSH” with the letter H as...
Introduction To Programming Using Visual Basic (11th Edition)
Explain the different aspects of the cost of a programming language.
Concepts of Programming Languages (11th Edition)
In some languages you must use a library function to raise a number to a power.
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
The ________ object is assumed to exist and it is not necessary to include it as an object when referring to it...
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
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 codearrow_forwardWrite a recursive method that parses a binary number as astring into a decimal integer. The method header is public static int bin2Dec(String binaryString) Write a test program that prompts the user to enter a binary string and displaysits decimal equivalent.arrow_forwardJava 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_forward
- Please Give answer in C# Write a recursive method which sums all the even numbers up to a given number. For example if you call it with 10, it would return 30 because 10+8+6+4+2=30 Write a RECURSIVE method called sumEven It must take in an int (the max you wish to sum to) It must return an int (the sum) If it's passed in an even number it should sum the number passed in with all the even numbers before it. For example if passed 8, it would sum 8+6+4+2=20 If it's passed an odd number it should still sum only the EVEN numbers. What we mean is that sumEven(9) should return 8+6+4+2=20. Not 9+7+5+3+1. Hint: You'll have an if statement with the base condition, an else if for even and an else if for odd. In the case of odd, just call yourself with the next lowest even number. In your main method, open a file called "Carlton.txt" for writing. Use a loop to call the method above multiple times and print a line to the file for each iteration of the loop: The sum of even numbers up to 0 is 0 The…arrow_forwardWrite a recursive method that returns a string of all positive, prime numbers less than or equal to a given value n. Use this header: String primeList (int n) For example, primeList (10) returns "7532" because the range 10 down to 0 includes the prime numbers 7, 5, 3, 2. Here are a few more examples. Returned Input n Notes String Any value less than 2 the returned string is empty 2 "2" "32" 7. "7532" 10 "7532" returned string has values 13, 11, 7, 5, 3, 2 15 "13117532" Note: A prime number is a whole number greater than 1, and it is divisible only by itself or the number 1. For example, 2, 3, 5, 7, 11, 13, 17, etc are all prime numbers. Here is a method that checks if a given number is prime: boolean isPrime(int n) { /method returns true if n is prime, otherdse it returns false if(n<2) return false; for (Int 1- 2; i < n; i++) //condition could also be icMath.sqrt(n) if(n %i -- 0) return false; return true;arrow_forwardWrite a recursive method tripleChar(String s, char c) that takes a string s and a character c. The method returns the string s with all the occurrences of c repeated 3 times.arrow_forward
- Write a recursive method that for a positive integer returns a string with commas in the appropriate places, for example, putCommas(1234567) returns the string “1,234,567.”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_forwardWrite a recursive method oddSum that takes a positive odd integer n and returns the sum of odd integers from 1 to n.arrow_forward
- Write 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_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_forwardjava 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_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