Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>What about it isn't working? Either way, I believe what you're missing is that you're continually getting the same substring, which will be the first number of the string: <code>int nextDigit = ninedigitNum.substring(0,1);</code>. In addition, you're going to want to use an <code>int</code>, not a <code>String</code>; you can technically convert from String to int if desired, but the problem itself calls for an int.</p> <p>There are two ways to do this that jump to mind. I would do this by realizing that mod in powers of 10 will give you the respective digit of an integer, but the easier way is to convert to a char array and then access directly. Note that there's no error checking here; you'll have to add that yourself. In addition, there are a LOT of 'magic numbers' here: good code typically has very, very few. I would recommend learning more data structures before attempting problems like these; to be honest there's very few things you can do without at least arrays and linked lists.</p> <pre><code>char[] ISBN = ninedigitNum.toCharArray(); //Process each number int total = 0; for(int i=0; i&lt;9; i++){ int current_int = Integer.parseInt(ISBN[i]); total += current_int * (10 - i) } //Find value of d1 for(int i=0; i&lt;9; i++){ if(((total + i) % 11) == 0){ total += i*100000000; break; } } return total; </code></pre> <p>In general: Use print outs with <code>System.out.println(x);</code> or use your compiler's debugger to see what's going on during processing.</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