Note that there are some explanatory texts on larger screens.

plurals
  1. POstring comparing doesn't return right answere
    text
    copied!<p>I want to compare 2 strings with eachother with the compareTo() function.</p> <p>example:</p> <pre><code>int result = "650".compareTo("651"); if(result &lt; 0){ System.out.println("smaller"); } else if(result &gt; 0){ System.out.println("bigger"); } else { System.out.println("equals"); } System.out.println(result); </code></pre> <p>this will output smaller which is correct.</p> <p>example 2:</p> <pre><code>int result = "650".compareTo("1000"); if(result &lt; 0){ System.out.println("smaller"); } else if(result &gt; 0){ System.out.println("bigger"); } else { System.out.println("equals"); } System.out.println(result); </code></pre> <p>This will return as output bigger. Which is kinda strange as 650 as number is smaller than 1000.</p> <p>How's that and how can i change it? (yes the numbers need to be in text format).</p> <p>I want to do this:</p> <pre><code>int result = "650/65".compareTo("1050/50"); if(result &lt; 0){ System.out.println("smaller"); } else if(result &gt; 0){ System.out.println("bigger"); } else { System.out.println("equals"); } </code></pre> <p>This returns that "650/65" is bigger than "1050/50" yet in fact it is smaller.</p> <p><strong>EDIT</strong></p> <p>I've worked out the cases and this is how it is now:</p> <pre><code>String maat = "650/65"; int subMaatB = 0; int subMaatA = 0; if(maat.contains("/")){ try{ subMaatA = Integer.parseInt(maat.substring(0, maat.lastIndexOf("/"))); subMaatB = Integer.parseInt(maat.substring(maat.lastIndexOf("/")+1)); } catch (NumberFormatException e){ } } boolean resultA = subMaatA &gt;= 440; boolean resultB = subMaatB &gt;= 65; boolean resultC = subMaatA &lt;= 1050; boolean resultD = subMaatB &lt;= 50; if(resultA &amp;&amp; resultB &amp;&amp; resultC &amp;&amp; resultD){ System.out.println("BIGGER"); } else { System.out.println("Smaller"); } </code></pre> <p>So the case is, Maat has to be within a range of 440/65 and 1050/50. Maat should be between the range i've mentioned before.</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