import java.util.*;
class Ideone {
public static void main
(String[] args
) { ImprimeLista(SeparaDigitos(12345));
ImprimeLista(SeparaDigitos(-123));
ImprimeLista(SeparaDigitosNegativo(-123));
ImprimeLista(SeparaDigitosNegativo(123));
}
public static List<Integer> SeparaDigitos(int valor) {
List<Integer> numerosGerados = new ArrayList<>();
int positivo
= Math.
abs(valor
); int tamanho
= (int)(Math.
log10(positivo
) + 1); int posicao = 0;
while(posicao < tamanho) {
int digito
= valor
/ (int)Math.
pow(10, tamanho
- posicao
- 1) * Integer.
signum(valor
); numerosGerados.add(digito);
valor
%= digito
* Math.
pow(10, tamanho
- posicao
- 1); posicao++;
}
return numerosGerados;
}
public static List<Integer> SeparaDigitosNegativo(int valor) {
List<Integer> numerosGerados = new ArrayList<>();
int positivo
= Math.
abs(valor
); int tamanho
= (int)(Math.
log10(positivo
) + 1); int posicao = 0;
while(posicao < tamanho) {
int digito
= valor
/ (int)Math.
pow(10, tamanho
- posicao
- 1) * (posicao
== 0 ? 1 : Integer.
signum(valor
)); numerosGerados.add(digito);
valor
%= digito
* Math.
pow(10, tamanho
- posicao
- 1); posicao++;
}
return numerosGerados;
}
public static void ImprimeLista(List<Integer> lista) {
for (int item : lista) {
}
}
}
ICAgIGltcG9ydCBqYXZhLnV0aWwuKjsKCiAgICBjbGFzcyBJZGVvbmUgewogICAgCXB1YmxpYyBzdGF0aWMgdm9pZCBtYWluIChTdHJpbmdbXSBhcmdzKQl7CiAgICAJCUltcHJpbWVMaXN0YShTZXBhcmFEaWdpdG9zKDEyMzQ1KSk7CiAgICAJCUltcHJpbWVMaXN0YShTZXBhcmFEaWdpdG9zKC0xMjMpKTsKICAgIAkJSW1wcmltZUxpc3RhKFNlcGFyYURpZ2l0b3NOZWdhdGl2bygtMTIzKSk7CiAgICAJCUltcHJpbWVMaXN0YShTZXBhcmFEaWdpdG9zTmVnYXRpdm8oMTIzKSk7CiAgICAJfQogICAgCXB1YmxpYyBzdGF0aWMgTGlzdDxJbnRlZ2VyPiB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