Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String number = scanner.nextLine();
- int n=0;
- for(int i = 0; i < number.length(); i++){
- char ch = number.charAt(i);
- if(Character.isDigit(ch)){
- n += ch - '0';
- }
- }
- while(n>9){
- int newN = 0;
- while(n>0){
- newN += n % 10;
- n /= 10;
- }
- n = newN;
- }
- System.out.println(n);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement