The following code is for calculating the sum of digits anddisplaying the highes
ID: 3615359 • Letter: T
Question
The following code is for calculating the sum of digits anddisplaying the highest and lowest value. I could display the sumand highest value, but the lowest value did not display. Pleasehelp me to display the lowest value. Any answer will beappreciated!!! Thank you!!import java.util.*;
public class SumDigits
{
public static void main(String[] args)
{
// Create a Scanner object toread keyboard input.
Scanner keyboard = newScanner(System.in);
// Get number.
System.out.print("EnterNumber:");
String digits =keyboard.nextLine();
int[] a = newint[digits.length()];
int max = 0;
int min = 0;
int sum = 0;
for (int i = 0; i <digits.length(); i++)
{
a[i] =Integer.parseInt(digits.substring(i,i+1));
if(a[i]> max)
max = a[i];
elseif(a[i] < min)
min = a[i];
sum = sum+ a[i];
}
System.out.print("The sum ofthe digits is: ");
System.out.println(sum);
System.out.println("Thelowest digit is " + min);
System.out.println("Thehighest digit is " + max);
}
}