Write a program to input a number. Find the sum of digits and the number of digits. Display the output
Using of loop
Correct answers will be marked as branilist
Answers
Answered by
0
import java.util.Scanner;
public class KboatDigitSum
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter a number: ");
int n = in.nextInt();
int sum = 0, count = 0;
while (n != 0) {
int d = n % 10;
sum += d;
count++;
n /= 10;
}
System.out.println("Sum of digits = " + sum);
System.out.println("Number of digits = " + count);
}
}
Output :
Enter a number : 7359
Sum of digits = 24
Number of digits = 4
Answered by
0
you can do this in qb 64.
it is the easiest coding software.
Similar questions
Computer Science,
2 days ago
English,
2 days ago
English,
2 days ago
Social Sciences,
5 days ago
Biology,
5 days ago
Science,
8 months ago