Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Main {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- double a = input.nextInt();
- double result = 0;
- double test = 0;
- double test1 =0;
- if (a < 0) {
- a = a * -1;
- }
- result = result + (a % 10);
- for (int j = 0; j < a; j++) {
- a = a / 10;
- result = result + Math.floor(a % 10);
- test = result;
- if (a < 10) {
- break;
- }
- }
- if (test > 9) {
- result = 0;
- result= result+ (test % 10);
- for (int i = 0; i <result; i++) {
- test = test/10;
- result = result + Math.floor(test % 10);
- if (test < 10) {
- break;
- }
- }
- test1=result;
- }
- else {
- System.out.println(result);
- }
- test=test1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement