Skip to content

Instantly share code, notes, and snippets.

@folivetti
Created March 5, 2017 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save folivetti/b212db56d63c32c9bfb8e0f3a7fa3119 to your computer and use it in GitHub Desktop.
Save folivetti/b212db56d63c32c9bfb8e0f3a7fa3119 to your computer and use it in GitHub Desktop.
import java.util.Scanner;
class Main {
public static int somaDigitos(int x) {
int resto, soma = 0;
while (x!=0) {
resto = x%10;
soma = soma + resto;
x = x/10;
}
return soma;
}
public static void main(String[] args) {
int x, persistencia = 0;
Scanner leitor = new Scanner(System.in);
x = leitor.nextInt();
while (x>9) {
x = somaDigitos(x);
persistencia = persistencia + 1;
}
System.out.println(persistencia);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment