Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class crookeddigits {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. String n = scanner.nextLine().toString().replaceAll("\\.", "").replaceAll("-","");
  7. int a = 0;
  8. for (int i = 0; i < n.length(); i++) {
  9. a += Character.digit(n.charAt(i), 10);
  10. }
  11.  
  12.  
  13. String b ="";
  14.  
  15. if (a > 9) {
  16. while(true) {
  17. if (a <= 9) {
  18. System.out.println(a);
  19. break;
  20. } else {
  21. b = a+"";
  22. a = 0;
  23. for (int i = 0; i < b.length(); i++) {
  24. a += Character.digit(b.charAt(i), 10);
  25. }
  26. }
  27. }
  28. } else {
  29. System.out.println(a);
  30. }
  31.  
  32.  
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement