Skip to content

Instantly share code, notes, and snippets.

@rhynl
Created August 24, 2017 23:44
Show Gist options
  • Select an option

  • Save rhynl/b1c768e742be8a0b5ee9a2843909042a to your computer and use it in GitHub Desktop.

Select an option

Save rhynl/b1c768e742be8a0b5ee9a2843909042a to your computer and use it in GitHub Desktop.
package javaapplication5;
import java.util.Scanner;
public class JavaApplication5 {
static Scanner keyboard = new Scanner(System.in);
public static void main(String[] args) {
String num = "";
num = keyboard.next();
int suma = 0;
int digitos = num.length();
while(true) {
for (int i = 0; i < digitos; i++) {
suma += Integer.parseInt(String.valueOf(num.charAt(i)));
}
if (suma < 10) {
break;
} else {
num = String.valueOf(suma);
digitos = num.length();
suma = 0;
}
}
System.out.println(suma);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment