-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdigital.java
More file actions
31 lines (27 loc) · 808 Bytes
/
digital.java
File metadata and controls
31 lines (27 loc) · 808 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
import java.util.Scanner;
//digital root adds digits of a number
//if the sum of those digits does not produce a single number
//the addition continues
public class digital {
static int number;
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Please enter a number ");
number = sc.nextInt();
sc.close();
int result = root(number);
System.out.print("The digital root of "+ number + " is "+ result );
}
public static int root(int number){
int sum = 0;
while (number > 10){
sum = 0;
while (number > 0){
sum += number%10;
number/=10;
}
number = sum;
}
return number;
}
}