class Teste {
int sa = a.length();
int sb = b.length();
if (sa == sb) return a.compareTo(b);
int dif = sa > sb ? sa - sb : sb - sa;
StringBuilder pad = new StringBuilder(sa > sb ? sa : sb);
for (int i = 0; i < dif; i++) {
pad.append('0');
}
String c
= sa
> sb
? a
: pad.
append(a
).
toString(); String d
= sa
> sb
? pad.
append(b
).
toString() : b
; return c.compareTo(d);
}
public static void main
(String[] args
) { System.
out.
println(seuComparador
("0",
"3")); System.
out.
println(seuComparador
("10",
"3")); System.
out.
println(seuComparador
("007",
"300")); System.
out.
println(seuComparador
("40",
"040")); }
}
Y2xhc3MgVGVzdGUgewoKICAgIHB1YmxpYyBzdGF0aWMgaW50IHNldUNvbXBhcmFkb3IoU3RyaW5nIGEsIFN0cmluZyBiKSB7CiAgICAgICAgaW50IHNhID0gYS5sZW5ndGgoKTsKICAgICAgICBpbnQgc2IgPSBiLmxlbmd0aCgpOwogICAgICAgIGlmIChzYSA9PSBzYikgcmV0dXJuIGEuY29tcGFyZVRvKGIpOwogICAgICAgIGludCBkaWYgPSBzYSA+IHNiID8gc2EgLSBzYiA6IHNiIC0gc2E7CgogICAgICAgIFN0cmluZ0J1aWxkZXIgcGFkID0gbmV3IFN0cmluZ0J1aWxkZXIoc2EgPiBzYiA/IHNhIDogc2IpOwogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgZGlmOyBpKyspIHsKICAgICAgICAgICAgcGFkLmFwcGVuZCgnMCcpOwogICAgICAgIH0KICAgICAgICAKICAgICAgICBTdHJpbmcgYyA9IHNhID4gc2IgPyBhIDogcGFkLmFwcGVuZChhKS50b1N0cmluZygpOwogICAgICAgIFN0cmluZyBkID0gc2EgPiBzYiA/IHBhZC5hcHBlbmQoYikudG9TdHJpbmcoKSA6IGI7CiAgICAgICAgcmV0dXJuIGMuY29tcGFyZVRvKGQpOwogICAgfQoKICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHsKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oc2V1Q29tcGFyYWRvcigiMCIsICIzIikpOwogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbihzZXVDb21wYXJhZG9yKCIxMCIsICIzIikpOwogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbihzZXVDb21wYXJhZG9yKCIwMDciLCAiMzAwIikpOwogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbihzZXVDb21wYXJhZG9yKCI0MCIsICIwNDAiKSk7CiAgICB9Cn0=