Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are doing bitwise operations here: <code>if(!characterAtEnd.equals(String.valueOf(0|1|2|3|4|5|6|7|8|9)))</code></p> <p>Check out the difference between <code>|</code> and <code>||</code></p> <p>This bit of code should accomplish your task using regular expressions:</p> <pre><code>String code = "45m4av7"; if (!code.matches("^.+?\\d$")){ System.out.println("INVALID CRC CODE"); } </code></pre> <p>Also, for reference, this method sometimes comes in handy in similar situations:</p> <pre><code>/* returns true if someString actually ends with the specified suffix */ someString.endsWith(suffix); </code></pre> <p>As <code>.endswith(suffix)</code> does not take regular expressions, if you wanted to go through all possible lower-case alphabet values, you'd need to do something like this:</p> <pre><code>/* ASCII approach */ String s = "hello"; boolean endsInLetter = false; for (int i = 97; i &lt;= 122; i++) { if (s.endsWith(String.valueOf(Character.toChars(i)))) { endsInLetter = true; } } System.out.println(endsInLetter); /* String approach */ String alphabet = "abcdefghijklmnopqrstuvwxyz"; boolean endsInLetter2 = false; for (int i = 0; i &lt; alphabet.length(); i++) { if (s.endsWith(String.valueOf(alphabet.charAt(i)))) { endsInLetter2 = true; } } System.out.println(endsInLetter2); </code></pre> <p>Note that neither of the aforementioned approaches are a good idea - they are clunky and rather inefficient. </p> <p>Going off of the ASCII approach, you could even do something like this:</p> <p>ASCII reference : <a href="http://www.asciitable.com/" rel="nofollow">http://www.asciitable.com/</a></p> <pre><code>int i = (int)code.charAt(code.length() - 1); /* Corresponding ASCII values to digits */ if(i &lt;= 57 &amp;&amp; i &gt;= 48){ System.out.println("Last char is a digit!"); } </code></pre> <p>If you want a one-liner, stick to regular expressions, for example:</p> <pre><code>System.out.println((!code.matches("^.+?\\d$")? "Invalid CRC Code" : "Valid CRC Code")); </code></pre> <p>I hope this helps! </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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