Write java program to input an integer. Compute and print the sum of all the digits and count of digits. Example: Input : N = 2854 Output: Sum of digits and Count of digits
Answers
Answered by
2
Answer:
Program:-
import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int n,a=0,s=0,c=0;
System.out.println("Enter the number");
n=in.nextInt();
while(n!=0)
{
a=n%10;
s=s+a;//Finds the sum
c++;//Counts the digits
n=n/10;
}
System.out.println("The sum of digits="+s);
System.out.println("The number of digits="+c);
in.close();
}
}
Output is attached.
Attachments:
Similar questions
English,
27 days ago
Math,
27 days ago
Social Sciences,
27 days ago
Physics,
1 month ago
Math,
9 months ago