Computer Science, asked by nfkhan115, 1 month ago

write a java program to input a number. find the sum of digits and the number of digits​

Answers

Answered by ngeniusraj
0

Answer:

below the program

Explanation:

import java.util.Scanner;

public class Digit_Sum

{

public static void main(String args[])

{

int m, n, sum = 0;

Scanner s = new Scanner(System.in);

System.out.print("Enter the number:");

m = s.nextInt();

while(m > 0)

{

n = m % 10;

sum = sum + n;

m = m / 10;

}

System.out.println("Sum of Digits:"+sum);

}

}

Output:

$ javac Digit_Sum.java

$ java Digit_Sum

Enter the number:456

Sum of Digits:15

Similar questions