package Q1;
/*(Sum the digits in an integer) Write a method that computes
* Use the following method header: public static int sumDigits
* (Hint: Use the \% operator to extract digits and the / oper
* For instance, to extract 4 from 234, use \( 234 \% 10 \) (= 4). To
* Use a loop to repeatedly extract and remove the digit unti
* that prompts the user to enter an integer then displays th
*/
public class \( Q 2 \) \{
public static void main(String[] args) \{
java.util.Scanner input = new java.util.Scanner(System. \( \boldsymbol{i} \)
System.out.print("Enter an Integer: ");
long \( \mathrm{n}= \) input. nextLong();
System.out.print("The sum of digits in "+n+" is "+ sum
\}
public static int sumDigits(long \( n \) ) \{
int sum \( =0 \);
while \( (\mathrm{n}>0) \) \{ sum \( +=n \% 10 ; \)
n \( /=10 \);
\}
return sum;
\}
\}
Problems
Declaration
Console \( \times \)