Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question
Java, I am not displaying my results correct. It should add up the digits in the string. input string |result for the sumIt Recursion functions and a findMax function that finds the largest number in a string "1d2d3d" | 6 total "55" |10 total "xx" | 0 total "12x8" |12 Max number "012x88" |88 Max Number "012x88ttttt9xe33ppp100" |100 Max Number public class Finder { //Write two recursive functions, both of which will parse any length string that consists of digits and numbers. Both functions //should be in the same class and have the following signatures. //use the if/else statement , Find the base case and -1 till you get to base case //recursive function that adds up the digits in the String public static int sumIt(String s) { //if String length is less or equal to 1 retrun 1. if (s.length()<= 1){ //use Integer.praseInt(s) to convert string to Integer //returns the interger values return Integer.parseInt(s); }else{ //else if the CharAt(value in index at 0 = 1) is not equal to the last vaule in the string else {//return the numeric values of a char value + call the SumIt method with a substring = 1 return Character.getNumericValue(s.charAt(0) ) + sumIt(s.substring(1)); } } //write a recursion function that will find the largest interger in the string. public int findMax(String s,int max) {//check the characters of the string is greater than 0 max = 0; //check the vales in the string , vaules = i if(s.substring(0, 1).matches("[0-9]")) { // checks for number int a = Integer.parseInt(s.substring(0, 1)); // convert String to Interger //substring begin index, endindex) if(a > max) { return findMax(s.substring(1), a)-1; //if a is greater than the index value 1 } else return findMax(s.substring(1), max)-1; // else we just use the old max } else return findMax(s.substring(1), max)-1; // in case its not a num } // return max; // return max when all characters are gone. //input string result //"1d2d3d" 6 //"55" 10 //"xx" 0 //input string result //"12x8" 12 //"012x88" 88 //"012x88ttttt9xe33ppp100" 100 //Testing public static void main(String[] args) { String a = "12X8"; String b = "55"; String c = "xx"; String d = "12x8"; String e = "012x88"; String f = "012x88ttttt9xe33ppp100"; System.out.println (a); System.out.println (b); System.out.println (c); System.out.println (d); System.out.println (e); System.out.println (f); } }
SAVE
AI-Generated Solution
AI-generated content may present inaccurate or offensive content that does not represent bartleby’s views.
bartleby
Unlock instant AI solutions
Tap the button
to generate a solution
Click the button to generate
a solution
Knowledge Booster
Background pattern image
Similar questions
Recommended textbooks for you
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