Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This loop copies all characters except the last one which probably is not what you wanted:</p> <pre><code>//for loop to setup ARRAY ONE for(int i = 0; i &lt; stringLength-1; i++){ arrayOne[i] = myString.charAt(i); } </code></pre> <p>It should probably be fixed like this:</p> <pre><code>//for loop to setup ARRAY ONE for(int i = 0; i &lt; stringLength; i++) { arrayOne [i] = myString.charAt (i); } </code></pre> <p>Body of this loop:</p> <pre><code>//for loop to setup ARRAY TWO for (int i = stringLength-1; stringLength-1 &gt; i; i--) { arrayTwo [i] = myString.charAt (i); } </code></pre> <p>is never executed, because initial value of <code>i</code>: <code>stringLength - 1</code> does not satisfy loop condition: <code>stringLength - 1 &gt; i</code>.</p> <p>You should probably change it to be:</p> <pre><code>// For loop to setup ARRAY TWO for (int i = 0; i &lt; stringLength; i++) { arrayTwo [i] = myString.charAt (stringLength - i - 1); } </code></pre> <p>Also, after this loop:</p> <pre><code>// for loop checking if array indexes are equivalent in value (char) for (int i = 0; i &lt; stringLength-1; i++) { if (arrayOne [i] != arrayTwo [i]) { palindrome = false; } else { palindrome = true; } } </code></pre> <p>variable <code>palindrome</code> will contain result of last comparison only, so if all characters except the last ones were different but last characters were equal, <code>palindrome</code> will be <code>true</code> which is probably not what you wanted. Probably you should change the code like this:</p> <pre><code>palindrome = true; for (int i = 0; i &lt; stringLength; i++) { if (arrayOne [i] != arrayTwo [i]) { palindrome = false; } } </code></pre> <p>Note that I also changed <code>stringLength - 1</code> to <code>stringLength</code>, otherwise you were ignoring last characters.</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. 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