import java.util.*;
import java.lang.*;
import java.io.*;
class Ideone
{
{
System.
out.
println(foo
(1234567,
6)); // vai retornar os seis primeiros System.
out.
println(foo
(-2222666,
4)); // vai desconsiderar o '-' e retornar os 4 primeiros System.
out.
println(foo
(123,
10)); // vai retornar o próprio número. }
public static int foo(int number, int digits){
if(digits> str.length())
return number;
boolean isNegative = str.startsWith("-");
return Integer.
valueOf(str.
substring(0, isNegative
? digits
+ 1 : digits
)); }
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgpjbGFzcyBJZGVvbmUKewoJcHVibGljIHN0YXRpYyB2b2lkIG1haW4gKFN0cmluZ1tdIGFyZ3MpIHRocm93cyBqYXZhLmxhbmcuRXhjZXB0aW9uCgl7CgkJU3lzdGVtLm91dC5wcmludGxuKGZvbygxMjM0NTY3LCA2KSk7ICAvLyB2YWkgcmV0b3JuYXIgb3Mgc2VpcyBwcmltZWlyb3MKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oZm9vKC0yMjIyNjY2LCA0KSk7IC8vIHZhaSBkZXNjb25zaWRlcmFyIG8gJy0nIGUgcmV0b3JuYXIgb3MgNCBwcmltZWlyb3MKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oZm9vKDEyMywgMTApKTsgICAgIC8vIHZhaSByZXRvcm5hciBvIHByw7NwcmlvIG7Dum1lcm8uCgl9CgkKCXB1YmxpYyBzdGF0aWMgaW50IGZvbyhpbnQgbnVtYmVyLCBpbnQgZGlnaXRzKXsKICAgCQlTdHJpbmcgc3RyID0gSW50ZWdlci50b1N0cmluZyhudW1iZXIpOwogICAJCWlmKGRpZ2l0cz4gc3RyLmxlbmd0aCgpKQogICAgICAgCQlyZXR1cm4gbnVtYmVyOwoKICAgIAlib29sZWFuIGlzTmVnYXRpdmUgPSBzdHIuc3RhcnRzV2l0aCgiLSIpOwogICAgCXJldHVybiBJbnRlZ2VyLnZhbHVlT2Yoc3RyLnN1YnN0cmluZygwLCBpc05lZ2F0aXZlID8gZGlnaXRzICsgMSA6IGRpZ2l0cykpOwoJfQp9