UVA 10922 Java

  1. import java.util.*;
  2. import static java.lang.System.*;
  3.  
  4. public class main{
  5. public static void main(String[] args) {
  6. Scanner sc=new Scanner(System.in);
  7. while(sc.hasNextLine())
  8. {
  9. String input = sc.nextLine();
  10. if(input.equals("0"))
  11. break;
  12. String str = input;
  13. int count = str.equals("9") ? 1 : 0;
  14. while(str.length() != 1)
  15. {
  16. int sum = 0;
  17. for(int i = 0; i < str.length(); i++)
  18. sum += str.charAt(i) - '0';
  19. if(sum % 9 == 0)
  20. count ++;
  21. else
  22. break;
  23. str = Integer.toString(sum);
  24. }
  25. if(count > 0)
  26. System.out.printf("%s is a multiple of 9 and has 9-degree %d.\r\n", input, count);
  27. else
  28. System.out.printf("%s is not a multiple of 9.\r\n", input);
  29. }
  30. }
  31. };
  32.  

留言

這個網誌中的熱門文章

C# 井字遊戲