Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Main {
  4.  
  5. public static void main(String[] args) {
  6. Scanner input = new Scanner(System.in);
  7. double a = input.nextInt();
  8. double result = 0;
  9. double test = 0;
  10. double test1 =0;
  11.  
  12. if (a < 0) {
  13. a = a * -1;
  14. }
  15. result = result + (a % 10);
  16.  
  17. for (int j = 0; j < a; j++) {
  18. a = a / 10;
  19. result = result + Math.floor(a % 10);
  20. test = result;
  21.  
  22. if (a < 10) {
  23. break;
  24. }
  25. }
  26. if (test > 9) {
  27. result = 0;
  28. result= result+ (test % 10);
  29.  
  30. for (int i = 0; i <result; i++) {
  31. test = test/10;
  32. result = result + Math.floor(test % 10);
  33. if (test < 10) {
  34. break;
  35. }
  36. }
  37. test1=result;
  38. }
  39. else {
  40. System.out.println(result);
  41.  
  42. }
  43. test=test1;
  44.  
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement