Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
917 B
2
Indexable
Never
import java.util.Scanner;
public class Main{
    //by Alarm Tran
    public static boolean isSimple(int n){
        if(n>=0 && n<10){
            return true;
        }
        return false;
    }
    public static int sumDigit(int n){
        int s=0;
        while(n>0){
            s+=n%10;
            n/=10;
        }
        return s;
    }
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        if(isSimple(n)){
            System.out.println(n/10);
        }else{
            boolean check = isSimple(n);
            while(check==false){
                int n1 = sumDigit(n);
                if(isSimple(n1)){
                    System.out.println(n1);
                    check = isSimple(n1);
                }else{
                    n = n1;
                }
            }
        }
    }
}