forked from Abhijith14/JavaElab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSumofalldigits.java
More file actions
35 lines (26 loc) · 34.3 KB
/
Sumofalldigits.java
File metadata and controls
35 lines (26 loc) · 34.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//Q. 3:
//Sumofalldigits(InputandOutputStatemen)
/*
You're given an integer N. Write a program to calculate the sum of all the digits of N.
Input
The input integer N
Output
Calculate the sum of digits of N.
*/
import java.io.*;
import java.util.Scanner;
public class TestClass {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
//System.out.println(N);
//int len = String.valueOf(N).length();
int i = N, rem = 0, s = 0;
while (i != 0){
rem = i % 10;
i = i / 10;
s = s + rem;
}
System.out.println(s);
}
}