You are rounding your results at 2 decimal places. Which makes you probably think they are exactly 0.0
, but they are not.
I think you should have it the other way around: if it contains 0.0 and there is only one element, it is OK. And if it contains more then one element it is not OK, so stop! Besides from that and as far as I can see, your code should work. Maybe you are confused about what your application is actually doing. Try to check if it works by printing. I also think that it should return a boolean
instead.
public static boolean checkSolution(double[][] matrix, double[] vector)
{
HashSet<Double> arraySet = new HashSet<Double>();
for (int line = 0; line < matrix.length; line++)
{
arraySet.clear();
for (int column = 0; column < matrix[line].length; column++)
{
arraySet.add(matrix[line][column]);
}
if (!(arraySet.size() == 1) || !(arraySet.contains(0.0)))
{
return false;
}
}
return true;
}