Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Bartleby Related Questions Icon
Related questions
Question
Write a recursive method called digitCount() that takes two integers, n and m as a parameter and returns the number of digits in n that are equal to m. Assume that n≥0 and 0≤m≤9
Ex: If the input is:
34443215 4
3
import java.util.Scanner;
public class LabProgram {
/* TODO: Write recursive digitCount() method here. */
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int digits;
int n= scnr.nextInt();
int m= scnr.nextInt();
digits = digitCount(n, m);
System.out.println(digits);
}
}
Transcribed Image Text:8.6 LAB: Count the digits that are larger than a treshhold
Write a recursive method called digitCount() that takes two integers, n and m as a parameter and returns the number of digits in n that are
equal to m. Assume that n20 and 0<m<9
Ex: If the input is:
34443215 4
3
412158.2147478.qx3zqy7
LAB
ACTIVITY
ANM&in ∞ N
1 import
java.util.Scanner;
3 public class LabProgram {
2
4
5
6
8
9
7 public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int digits;
10
11
8.6.1: LAB: Count the digits that are larger than a treshhold
in 10
12
13
14
15 }
16 }
17
/* TODO: Write recursive digitCount() method here. */
int n= scnr.nextInt ();
int m= scnr.nextInt ();
digits digitCount (n, m);
System.out.println(digits);
LabProgram.java
=
0/10
Load default template...
Expert Solution
Check Markarrow_forward
Overview
In this question we have to write a Java Code for digitCount() in recursive method.
Let's code
bartleby
Step by stepSolved in 3 steps with 1 images
Knowledge Booster
Background pattern image
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 recursive method called add(int n). This method adds the integers from 0 to some value n. For example, the call to add(4) would return 10 (4+3+2+1=10).arrow_forwardWrite 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. 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.arrow_forwardWrite 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){...arrow_forward
- Given an array of N integer elements, How can one write a recursive Java method named findMax that returns the largest integer of the array. Without the Math.max() library method?arrow_forwardThe following recursive method called z is created. This method accepts two parameters: A string s, and an integer index The code in the method is: if (index == s.length()) return ""; <------ base case if(index % 2 == 0) return ""+ s.charAt(index) + z(s,index+1); <---- recursive call else return z(s,index+1); <----- recursive call What would be the output with the call: z("javajavajava",0);arrow_forwardWrite code to complete raise ToPower(). Sample output if userBase is 4 and userExponent is 2 is shown below. Note: This example is for practicing recursion; a non-recursive method, or using the built-in method pow(), would be more common. 4^2 = 16 1 import java.util.Scanner; 2 3 public class Exponent Method { 4 public static int raise ToPower (int baseVal, int exponentVal) { 5 int resultVal; 6700 a 8 9 10 11 12 13 14 15 16 17 } if (exponentval resultVal = 1; == } else { } return resultVal; resultVal = 0) { baseVal * /* Your solution goes here */; public static void main (String [] args) {arrow_forward
- For JAVA.arrow_forwardConsider the recursive method myPrint: public void myPrint (int n) if (n < 10) System.out.print(n); else { int m = n % 10; %3D System.out.print (m) ; myPrint (n / 10); What is printed for the call myPrint (10)?arrow_forwardConsider a recursive method below. static void mysteryRecursion (String x) { if (x.length() < 1) { System.out.println(x); } else { System.out.println (x.charAt (0) + " " + x.charAt (x.length () - 1)) ; mysteryRecursion (x.substring (1, x.length () - 1)); What gets printed if I make the method call mysteryRecursion("helloworld");arrow_forward
- The method is in fact faulty. Give a test input (String) that will make the method to fail -- i.e., it will throw an exception when it is executed with the input).arrow_forwardWhen looking at this code making recursive calls, how would I identify how many recursive calls are being made?arrow_forwardWrite a recursive method in java that sums all values between s and n inclusive /* assume s is less than or equal to n to start */ public static int sum(int s, int n) { }arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education