how to test if Long ends with a number pattern on JAVA?

i agree with @shmosel solution. But it’s true just when second number has only 3 digits.

boolean compareTail(long one, long two) {
    int digits =(int) Math.log10(two)+1;
    long formated = one % ((long) Math.pow(10, digits));
    return formated == two;
 }

Leave a Comment