Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- // write your code here
- Scanner sc = new Scanner(System.in);
- String digit = sc.nextLine();
- String number = digit.replace(".","");
- String Number = number.replace("-", "");
- int n = Integer.parseInt(Number);
- int sum =0;
- while (n > 0 || sum > 9)
- {
- if (n == 0) {
- n = sum;
- sum = 0;
- }
- sum += n % 10;
- n /= 10;
- }
- System.out.println(sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement