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); } }

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 6PE
icon
Related questions
Question
100%
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); } }
AI-Generated Solution
AI-generated content may present inaccurate or offensive content that does not represent bartleby’s views.
steps

Unlock instant AI solutions

Tap the button
to generate a solution

Similar questions
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning