Advertisement
Mishakis

Mock1_1

Oct 14th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.64 KB | None | 0 0
  1.  
  2.  
  3.  
  4. import java.util.Scanner;
  5.  
  6.  
  7. public class Main {
  8.  
  9.  
  10.  
  11.     public static void main(String[] args) {
  12.         Scanner scanner = new Scanner(System.in);
  13.  
  14.         String number = scanner.nextLine();
  15.         int n=0;
  16.  
  17.         for(int i = 0; i < number.length(); i++){
  18.             char ch = number.charAt(i);
  19.             if(Character.isDigit(ch)){
  20.                 n += ch - '0';
  21.  
  22.             }
  23.         }
  24.         while(n>9){
  25.             int newN = 0;
  26.  
  27.             while(n>0){
  28.                 newN += n % 10;
  29.                 n /= 10;
  30.             }
  31.  
  32.             n = newN;
  33.  
  34.  
  35.         }
  36.         System.out.println(n);
  37.     }
  38.  
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement