Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. import acm.program.*;
  2.  
  3. public class DigitalRoot extends ConsoleProgram {
  4. public void run() {
  5.  
  6. int number_user = readInt("Enter a number: ");
  7. int sum = 0;
  8.  
  9. if(number_user < 0) {
  10. println("Error");
  11. } else {
  12. while( number_user > 0 || sum >= 9) {
  13.  
  14. sum += number_user % 10;
  15. number_user /= 10;
  16.  
  17.  
  18.  
  19. }
  20. println("" + sum + "");
  21. }
  22. }
  23.  
  24.  
  25. public static void main(String[] args) {
  26. new DigitalRoot().start();
  27. }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement