Computer Science, asked by tiyarawat1, 5 months ago

Write a program to input a number. Find the sum of digits and the number of digits. Display the output.
Sample Input: 7359
Sum of digits = 24
Number of digits = 4​

Answers

Answered by Oreki
9

import java.util.Scanner;

public class Numbers {

public static void main(String[ ] args) {

System.out.print("Enter a number - ");

int number = new Scanner(System.in).nextInt( );

System.out.println("Number of Digits - " + (number + "").length( ));

int sum = 0;

for (int i = number; i != 0; i /= 10)

sum += i % 10;

System.out.println("Sum of digits - " + sum);

}

}

Similar questions