Created
August 24, 2017 23:44
-
-
Save rhynl/b1c768e742be8a0b5ee9a2843909042a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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