Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created July 7, 2014 16:11
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 Fhernd/4b9213d7641ff5992c8a to your computer and use it in GitHub Desktop.
Save Fhernd/4b9213d7641ff5992c8a to your computer and use it in GitHub Desktop.
Separa los digítios de un número entero.
import java.util.Scanner;
// Clase definida por el programador
public class SepararDigitos
{
// Método de clase
public static void main( String[] args )
{
int num; // Almacena el número digitado por el usuario
int temp; // Almacena cocientes y residuos
int dM; // Decenas de mil
int uM; // Unidades de mil
int cen; // Centenas
int dec; // Decenas
int uni; // Unidades
// Instanciar un objeto de tipo 'Scanner'
Scanner entrada = new Scanner( System.in );
// Solicitud y obtención del número
System.out.print( "Digite un número entero de 5 dígitos: " );
num = entrada.nextInt();
if( num >= 10000 )
{
if( num <= 99999)
{
dM = num / 10000;
temp = num % 10000;
uM = temp / 1000;
temp = temp % 1000;
cen = temp / 100;
temp = temp % 100;
dec = temp / 10;
temp = temp % 10;
uni = temp;
// Visualización de resultados
System.out.printf( "\n%d %d %d %d %d\n", dM, uM, cen, dec, uni);
} // fin de if
} // fin de if
// Salida
System.exit(0);
} // fin de main
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment