-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsumOfDigits.java
More file actions
38 lines (29 loc) · 826 Bytes
/
sumOfDigits.java
File metadata and controls
38 lines (29 loc) · 826 Bytes
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
36
37
38
/*
@author Muhammed Fatih ÖZDİL
@since 03/03/2021
*/
package algorithmExamples;
import java.util.Scanner;
public class sumOfDigits {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.print("enter integer:");
int number = scanner.nextInt();
if (number > 0 && number < 1000) {
int sum = 0;
while (true) {
sum += number % 10;
number /= 10;
if (number < 1) {
System.out.println(sum);
System.exit(0);
break;
}
}
break;
}
}
scanner.close();
}
}