Here is the question: Write a program that asks the user to enter a series of si
ID: 3615337 • Letter: H
Question
Here is the question:Write a program that asks the user to enter a series of singledigit numbers with nothing separating them. the program shoulddisplay the sum of all the single digit numbers in the string. Forexample, if the user enters 2514, the method should return 12,which is the sum of 2, 5, 1, and 4. The program should also displaythe highest and lowest digits in the string (Hint: convert thestring to an array).
I don't know my code is answering the above question, but I gotcorrect answer for summing up the digits:
java.util.*;
SumDigits
main(String[] args)
Scanner keyboard = Scanner(System.in);
System.out.print();
String digits = keyboard.nextLine();
[] b = [digits.length()];
String [] a = String[digits.length()];
sum = 0;
( i = 0; i < digits.length(); i++)
a[i] = digits.substring(i,i+1);
sum = sum + Integer.parseInt(a[i]);
System.out.print();
System.out.println(sum);
System.out.println( + Integer.MIN_VALUE);
System.out.println( + Integer.MAX_VALUE);
However, I cannot display the highest and lowest digits of what theuser typed. It displayed:
The lowest digits is -2147483648
The highest digits is 2147483647
So I think MIN_VALUE and MAX_VALUE is not appropriate code to findthe user's digits.
How should I change my code to display the highest and lowestdigits?
I really appreciate for any answers! Thank you.