In this tutorial, we will learn the java program to fetch the integers from the given strings and print the sum of integers digits present in the string.
Take any string as an input from the user and check for integers and if there are integers then return the sum of digits of integers.
Case1: If the user inputs the string ‘1%program897Language%’
Then the output should be ‘25’, where there is no character that is repeating.
Case2: If the user inputs the string ‘123!python!@456*’
Then the output should be ‘21’, where there is no character that is repeating.
Java Program to Find Sum of Integers in the String
In this example, the user input the string ‘Que123col567’. While iterating the character of the string, the digits were found using the isdigit() method and when this happens the if block start executing which is taking the sum of digits. Finally, the program will return the sum of those digits as the output of the program which is 24.