Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'd recommend using a <code>for</code> loop. I think it would be easier than what you are currently doing. <em>Generally</em> <code>for</code> loops go as such:</p> <pre><code>for(START POSITION, CONTROL, ITERATION PATTERN){ CODE } </code></pre> <p>I'd read more about <code>for</code> loops here: </p> <p><a href="http://www.tutorialspoint.com/java/java_loop_control.htm" rel="nofollow">http://www.tutorialspoint.com/java/java_loop_control.htm</a></p> <p><a href="http://docs.oracle.com/javase/tutorial/java/nutsandbolts/for.html" rel="nofollow">http://docs.oracle.com/javase/tutorial/java/nutsandbolts/for.html</a></p> <p>The <code>String</code> object has a method <code>.length()</code> which will be used for the control of the loop. You want to iterate by 2 (because that's how you're separating it the words). You also want to start at 1 (usually the starting position is 0 but in this case we want 1):</p> <pre><code>String word = "Daniel";//starting word String outputWord = "";//make it empty quotes so you can concatenate to it. //if the size of word is less than 2, then print so //else do the code below for(int i = 1; i &lt; word.length(); i = i+2){ outputWord = outputWord + word.get(i-1) + word.get(i) + "\n"; } //check if the length was of word was odd. if so, then add the last character to outputWord System.out.println(outputWord); </code></pre> <p><strong>NOTE</strong>: This will only working assuming your <code>word</code> variable is at least 2 in size. I'll leave that error handling up to you to write. You'll also want to handle in odd length cases as well. </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.
    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