Guest User

Untitled

a guest
Sep 30th, 2021
53
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5. public static void main(String[] args) {
  6. Scanner scanner = new Scanner(System.in);
  7.  
  8. String input = scanner.nextLine().replace(".","").replace("-","");
  9. double number = Double.parseDouble(input);
  10. while(number > 9 || number < 0) {
  11. number = sumDigits(number);
  12. }
  13. System.out.println((int)(number));
  14. }
  15.  
  16. private static double sumDigits(double input) {
  17. int sum = 0;
  18.  
  19. while (input > 0) {
  20. sum += input % 10;
  21. input /= 10;
  22. }
  23. return sum;
  24. }
  25. }
  26.  
RAW Paste Data