Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You are very likely doing a reference equals rather than a comparison equals. When using the capital lettered versions of the numeric types, you should use <code>one.equals(two)</code>.</p> <p>Ensure that the value of <code>tempPoint[2]</code> is <strong>exactly</strong> <code>2.0</code>. As a <code>double</code>, it's very possible that they are close, but not equal.</p> <p>You also might find using a foreach loop easier to follow:</p> <pre><code>private List&lt;Double[]&gt; bestPoints(List&lt;Double[]&gt; includedPoints) { List&lt;Double[]&gt; bestPoints = new ArrayList&lt;Double[]&gt;(); for (Double[] tempPoint : tempPoints) { if (tempPoint[2] == maxCount) { bestPoints.add(new Double[] { tempPoint[0], tempPoint[1] }); } } return bestPoints; } </code></pre> <p>If the values are always integers, then cast them before checking equality (e.g., <code>(long)tempPoint[2] == (long)maxCount</code>). If you want exact matches from <code>double</code>s, then continue what you are doing (after ensuring the proper type of equal check, dependent on maxCount), but if you want <em>near</em> matches (if decimals are a concern rather than predefined constants), then use an epsilon value:</p> <pre><code>public static boolean doubleEquals(double val1, double val2, double epsilon) { return Math.abs(val1 - val2) &lt; epsilon; } public static boolean doubleEquals(double val1, double val2) { return doubleEquals(val1, val2, 1e-5); } </code></pre> <p>Obviously specify an epsilon value that makes sense for you.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload