Question: Language Is In Java. I need help in making my code output like the required text in the left, Specifically Make your program handle strange

Language Is In Java. I need help in making my code output like the required text in the left,
Specifically "Make your program handle strange input. Specifically, if they didn't enter a number, scan the String to find just the digits and piece those digits together to form a number."
 Language Is In Java. I need help in making my code
CURRENT CODE
import java.util.*;
public class SumNum {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str;
int sum = 0;
while (true) {
System.out.println("Enter a integer");
int a = 0, l = 0, m = 0;
str = sc.nextLine();
for (int i = 0; i
if (Character.isDigit(str.charAt(i))) {
l = 1;
m = str.charAt(i);
a = a * 10 + m - 48;
}
if (l == 0) {
System.out.println("There were no digits in that input.");
break;
} else {
sum += a;
System.out.println("Current sum: " + sum);
}
}
System.out.println("Final sum: " + sum);
}
}
output like the required text in the left, Specifically "Make your program
Test Case 3 - Failed Standard Input ..4993 969798re7 2gf jh3 df64f57 f121 x2e3errrw5ddd6 Required Output Your Program's Output Enter a integerin Well, that's not a number but here's what I extracted : 43 in Current sum: 43 Enter a integer in Well, that's not a number but here's what I extracted : 6787 in Current sum: 6830 in Enter a integer in Well, that's not a number but here's what I extracted : 2 Current sum: 6832 Enter a integert Well, that's not a number but here's what I extracted : 3 Current sum: 6835 in Enter a integer in Well, that's not a number but here's what I extracted : 451 Current sum: 6880 Enter a integer in Well, that's not a number but here's what I extracted : 211 Current sum: 6901 Enter a integer in Well, that's not a number but here's what I extracted : 123456n Current sum: 130357 In Enter a integer in There were no digits in that input. In Enter a integerin Current sum: 43 Enter a integer in Current sum: 6830 in Enter a integerlin Current sum: 6832 Enter a integer in Current sum: 6835 Enter a integer in Current sum: 6880 Enter a integer Current sum: 690111 Enter a integer in Current sum: 130357in Enter a integerin There were no digits in that input. An Final sum: 130357n (Your output is too short.) Ask the user for a bunch of integers. Show the sum of those numbers. Make your program handle strange input. Specifically, if they didn't enter a number, If the user enters something without any digits, end the program. Test Standard Input 10 end Required Output Enter a integerin Current sum: 5 Enter a integer In Current sum: 15 kn Enter a integer There were no digits in that input. In Final sum: 15

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!