import java.lang.*;
class Ideone {
System.
out.
println(PegaPrimirosDigitos
(12345678,
4)); System.
out.
println(PegaPrimirosDigitos
(-12345678,
4)); System.
out.
println(PegaPrimirosDigitos
(123,
4)); System.
out.
println(PegaPrimirosDigitos
(-12,
4)); System.
out.
println(PegaPrimirosDigitos
(0,
0)); }
public static int PegaPrimirosDigitos(int valor, int digitos) {
digitos
= Math.
max(1, digitos
); int positivo
= Math.
abs(valor
); if(digitos > texto.length()) {
return valor;
}
return Integer.
parseInt(texto.
substring(0, digitos
)) * Integer.
signum(valor
); }
}
aW1wb3J0IGphdmEubGFuZy4qOwoKY2xhc3MgSWRlb25lIHsKCXB1YmxpYyBzdGF0aWMgdm9pZCBtYWluIChTdHJpbmdbXSBhcmdzKSB0aHJvd3MgamF2YS5sYW5nLkV4Y2VwdGlvbiB7CgkJU3lzdGVtLm91dC5wcmludGxuKFBlZ2FQcmltaXJvc0RpZ2l0b3MoMTIzNDU2NzgsIDQpKTsKCQlTeXN0ZW0ub3V0LnByaW50bG4oUGVnYVByaW1pcm9zRGlnaXRvcygtMTIzNDU2NzgsIDQpKTsKCQlTeXN0ZW0ub3V0LnByaW50bG4oUGVnYVByaW1pcm9zRGlnaXRvcygxMjMsIDQpKTsKCQlTeXN0ZW0ub3V0LnByaW50bG4oUGVnYVByaW1pcm9zRGlnaXRvcygtMTIsIDQpKTsKCQlTeXN0ZW0ub3V0LnByaW50bG4oUGVnYVByaW1pcm9zRGlnaXRvcygwLCAwKSk7Cgl9CglwdWJsaWMgc3RhdGljIGludCBQZWdhUHJpbWlyb3NEaWdpdG9zKGludCB2YWxvciwgaW50IGRpZ2l0b3MpIHsKCQlkaWdpdG9zID0gTWF0aC5tYXgoMSwgZGlnaXRvcyk7CgkJaW50IHBvc2l0aXZvID0gTWF0aC5hYnModmFsb3IpOwoJICAgIFN0cmluZyB0ZXh0byA9IFN0cmluZy52YWx1ZU9mKHBvc2l0aXZvKTsKICAgICAgICBpZihkaWdpdG9zID4gdGV4dG8ubGVuZ3RoKCkpIHsKICAgICAgICAgICAgcmV0dXJuIHZhbG9yOwogICAgICAgIH0KCQlyZXR1cm4gSW50ZWdlci5wYXJzZUludCh0ZXh0by5zdWJzdHJpbmcoMCwgZGlnaXRvcykpICogSW50ZWdlci5zaWdudW0odmFsb3IpOwoJfQp9