Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Root {
- private static int sum( int a )
- {
- int ans = 0;
- while( a != 0 )
- {
- ans += a%10;
- a /= 10;
- }
- return ans;
- }
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int N = scan.nextInt();
- while (N != 0) {
- while( N >= 10 )
- {
- N = sum(N);
- }
- System.out.println("Digital Root: " + N);
- N = scan.nextInt();
- }
- scan.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement