Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 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;
  8.  
  9. if(number_user < 0) {
  10. println("Error");
  11. } else {
  12. while( sum > 0) {
  13. sum += number_user % 10;
  14. number_user /= 10;
  15.  
  16. }
  17. println("" + sum + "");
  18.  
  19. }
  20. }
  21.  
  22.  
  23. public static void main(String[] args) {
  24. new DigitalRoot().start();
  25. }
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement