Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Alright, I think I might know what you're trying to accomplish, though as others have mentioned it is a little unclear.</p> <p>To address the code you just posted, I don't think it'll behave the way you expect. For starters, the Boolean variable 'Check' accomplishes nothing at the moment. convert_to_numb is only called while Check is true, so it's redundant.</p> <p>Additionally, the sum isn't being stored anywhere as you loop through the string. Every time you obtain a sum, it overwrites the previous one.</p> <p>Your convert_to_numb method is even more troubling; it contains an infinite loop. Since Check is always set to 'true', you essentially have a while(true) loop that will never end.</p> <p><br></p> <p>I'm going to assume that your objective here is to parse whichever Strings are input into the program looking for groups of consecutive digits. Then you want to store these groups of digits as integers, perhaps in an array if you find multiple.</p> <p>Something like this might do the trick.</p> <pre class="lang-java prettyprint-override"><code>{ ArrayList&lt;Integer&gt; discovered = new ArrayList&lt;Integer&gt;(); for (String s : args) { // contains previous consecutive digits (if any) ArrayList&lt;Integer&gt; digits = new ArrayList&lt;Integer&gt;(); for (int i = 0; i &lt; s.length(); i++) { Character c = s.charAt(i); // add digit to digit array if (c.isDigit()) { digits.add(c.getNumericValue()) } // not a digit, so we clear the digit array else { // combine the array to form an integer if (! digits.isEmpty()) { int sum = 0; int counter = 0; for (Integer i : digits) { sum += i * Math.pow(10, counter); counter++; } discovered.add(sum); digits.clear(); } } } } } </code></pre> <p>Note the use of ArrayLists and the Integer and Character wrapper classes. These all provide functionality that helps deal with edge-cases. For example, I'm not sure that <code>(iter - 48)</code> part would have worked in all cases.</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