Find two missing elements from a sorted array in given range Looking for reviewers to suggest optimization and improvements, and to evaluate coding practices.

final class Variables {
    private final int x;
    private final int y;

    Variables(int x2, int y2) {
        this.x = x2;
        this.y = y2;
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    @Override public String toString()  { 
        return "x = " + x + " y = " + y;
    }
}

public final class FindMissing {

    private FindMissing() {};

    /**
 * Takes an input a sorted array with two variables that repeat in the
 * range. Remaining variable are consecutive. and returns two variables that repeats
 * 
 * eg: for a range of 1,2,3,4, a valid input is [1, 4], [1, 3] etc.
 * 
 * @param a : the sorted array.
 */
/*
 * Why is start needed ?
 * If start is not given then if a1 is empty how do we know if missing numbers were
 * [1, 2] or [4, 5] ??. 
 */
public static Variables sortedConsecutiveTwoMissing (int[] a, int startOfRange) {
    if (a == null) throw new NullPointerException("a1 cannot be null. ");

    int low = startOfRange;
    // calculating the highest value of the range. it needs to be 2 more than length since all elememts are consecutive.
    int high = startOfRange + (a.length - 1) + 2;

    int i = 0;
    boolean foundX = false;
    int x = 0; 

    while (i &lt; a.length) {
        if (a[i] != low) {
            if (foundX) {
                return new Variables(x, low);
            } else {
                x = low;
                foundX = true;
            }
        } else {
            i++;
        }
        low++;
    }

    return new Variables(x, high);
 }

public static void main(String[] args) {
        // unsortedConsecutiveTwoMissing
        int[] a6 = {1, 4};
        System.out.println("Expected 2 and 3, Actual " + sortedConsecutiveTwoMissing(a6, 1));
        // unsortedConsecutiveTwoMissing
        int[] a7 = {-4, -1};
        System.out.println("Expected -3 and -2, Actual " + sortedConsecutiveTwoMissing(a7, -4));
        int[] a8 = {-4, -3, -2, -1};
        System.out.println("Expected 0 and 1, Actual " + sortedConsecutiveTwoMissing(a8, -4));
        int[] a9 = {5};
        System.out.println("Expected 4 and 6, Actual " + sortedConsecutiveTwoMissing(a9, 4));
        }
     }
You say the problem is to find missing values from a 'Range', but your method only takes a start value, not an end value.... is this intentional? The method comment says:


  Takes an input a sorted array with two variables that repeat in the range. and returns two variables that repeats


The method does nothing of the sort though... it takes one variable, and there's no indication the values repeat, and it returns missing values, not repeats.

Additionally, the method name is sortedConsecutiveTwoMissing but there's nothing in the implementation that suggests that the values have to be consecutive at all...

Also you suggest the array is sorted, but not whether it is unique... for example, your code may break on (missing is 3 and 5):

0 1 2 2 4 4 6 6 7 8 9


General / Code Style


Variables like a1 make me want to look for a2, a3, etc. Unless it's obvious, don't use numbered variables.
int high = start + (a1.length - 1) + 2; should have a comment .... the + 2 is not obvious, and magic numbers should either be very obvious, or documented. That line still makes no sense to me at all.... and high is not used for anything reasonable anyway.
calculatedX is not a calculated anything


At this point I don't believe the code does what you suggest it should, so I don't believe the code works... downvote time.

Edit the code, make it work....