Sorry if I'm wrong, but I'm assuming for now that you want your method to return a smaller 2d array which contains some of the values of the given array, in which case you would need to change your method to this:
public static double[][] amountOTP(double [][] a, int x) {
double[][] b = new double[x][x];
x = Math.min(x, a.length);
for(int i = 0;i < x; i++)
for(int j = 0;j < x; j++)
b[i][j] = a[i][j];
return b;
}
This should work fine but feel free to comment and inform me if I left anything out or it doesn't work; I'm here to help. Anyways, I hope this works for you. (Also, if this isn't the answer you were looking for, feel free to tell me.)
Note: This should avoid IndexOutOfBounds exceptions, so it will still work correctly if the user gives an x value bigger than the size of a. The 2d array that this method returns will just have some values of zero where it couldn't find any numbers.