Test if a number is within 2 of a multiple of 10
You should read about congruent integers and modular arithmic. The distance of a number to a base is the minimum distance of its congruent value and its inverted congruent value.

 public boolean nearBase(int num, int base, int deviation) {

        // ..TODO check guards, normalize input or throw exceptions 
        // - base and deviation are expected strict positive integers
        // - deviation is expected smaller than base
        // - num is expected a positive integer

        var congruent = num % base;
        var inverted = base - congruent;
        var distance = Math.min(congruent, inverted);
        return distance &lt;= deviation;
    }

 // your method rewritten -&gt;
 public boolean nearTen(int num) {
        return nearBase(num, 10, 2);
    }