Advertisement
Monika_Monova

CrookedDigits

Aug 14th, 2019
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. package com.company;
  2.  
  3.  
  4. import java.util.Scanner;
  5.  
  6. public class Main {
  7.  
  8. public static void main(String[] args) {
  9. // write your code here
  10. Scanner sc = new Scanner(System.in);
  11. String digit = sc.nextLine();
  12. String number = digit.replace(".","");
  13. String Number = number.replace("-", "");
  14.  
  15.  
  16. int n = Integer.parseInt(Number);
  17.  
  18. int sum =0;
  19. while (n > 0 || sum > 9)
  20. {
  21. if (n == 0) {
  22. n = sum;
  23. sum = 0;
  24. }
  25. sum += n % 10;
  26. n /= 10;
  27. }
  28.  
  29.  
  30. System.out.println(sum);
  31.  
  32. }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement