Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You shouldn't use keywords such as "Integer" for variable identifiers.</p> <p>There are some lingering questions I have, but I would simply use Java's builtin <strong>split()</strong> function on strings and use <strong>regex</strong> to split the string into significant figures (ignoring ending and leading zeroes). Then return the sum of the length of the strings . Here is the code for pure integers.</p> <pre><code>String myint = "000100101111220000020000"; String[] sig_figs = myint.split("(^0+|0+$)"); int sum = 0; for(String fig : sig_figs) { sum += fig.length(); } return sum; </code></pre> <p>If we include floats, there are other rules you would have to consider, such as zeroes after a decimal point count except if they are preceded by all zeroes (3.00 has 3, 0.03 has 1). In this case, the regex regrettably becomes much more contrived, but I would use something like <code>"(^0+(\\.?)0*|(~\\.)0+$|\\.)"</code> to split on. See code below (Note -- still works on integers)</p> <pre><code>String myfloat = "0.0120"; String [] sig_figs = myfloat.split("(^0+(\\.?)0*|(~\\.)0+$|\\.)"); int sum = 0; for (String fig : sig_figs) { sum += fig.length(); } return sum; </code></pre> <p>Here's a quick look into the regex:</p> <p><code>^0+(\\.?)0*</code> means one or more leading zeroes (<code>0+</code>) followed optionally by a decimal (<code>\\.?</code>) and then zero or more zeroes (<code>0*</code>).</p> <p><code>(~\\.)0+$</code> means we want to take off ending zeroes (<code>0+$</code>), but only if they aren't preceded by a decimal (<code>(~\\.)</code>).</p> <p><code>\\.</code> means split whatever is left by the decimal point.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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