MCPcopy Create free account
hub / github.com/Manvityagi/PW-Skills-Java-Course-Codes / CountDigits

Class CountDigits

Lecture 08_Loops_1/src/CountDigits.java:3–17  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1import java.util.Scanner;
2
3public class CountDigits {
4 public static void main(String[] args) {
5 Scanner sc = new Scanner(System.in);
6 int n = sc.nextInt();
7 int sumOfDigits = 0;
8 int original_n = n;
9
10 while(n > 0) {
11 sumOfDigits += n % 10;
12 n = n / 10;
13 }
14
15 System.out.println("Sum of digits in " + original_n + " = " + sumOfDigits);
16 }
17}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected