title: Java for loop error
body: <p>I am trying to get user input for sortValues[] array using the for statement (enter character 1, enter character 2, etc). </p>
  
  <p>However, when I execute this, the program will not allow me to enter for character 2, instead skipping directly to character 3, as seen below. </p>
  
  <p><img src="https://i.stack.imgur.com/5tdrD.png" alt="enter image description here">     </p>
  
  <p>How to resolve this? The code is included below.</p>
  
  <p>thanks!</p>
  
  <pre><code>static public void s_1d_char () {
              int counter=0;
              int x=0;
              c.print("How many characters? ");
              counter = readInt();
  
              char[] sortValues = new char[counter+1];
  
              for (x=1;x&lt;=counter;x++) {
                      System.out.println("Enter character "+(x)+":");
                  sortValues[x] = readChar();
              }
      }
  </code></pre>
  
  <p>readChar implementation (this is from a library):</p>
  
  <pre><code>public synchronized char readChar ()
  {
  char result, ch;
  
  if (ungotChar != EMPTY_BUFFER)
  {
      result = (char) ungotChar;
      ungotChar = EMPTY_BUFFER;
      return (result);
  }
  
  if (lineBufferHead != lineBufferTail)
  {
      result = lineBuffer [lineBufferTail];
      lineBufferTail = (lineBufferTail + 1) % lineBuffer.length;
      return (result);
  }
  
  startRow = currentRow;
  startCol = currentCol;
  if (currentRow &gt; maxRow)
  {
      startRow++;
      currentCol = 1;
  }
  
  // Turn cursor on if necessary
  consoleCanvas.setCursorVisible (true);
  
  // Wait for a character to be entered
  while (true)
  {
      ch = getChar ();
  
      if (ch == '\n')
      {
      clearToEOL = false;
      if (echoOn)
          print ("\n");
      clearToEOL = true;
      lineBuffer [lineBufferHead] = '\n';
      lineBufferHead = (lineBufferHead + 1) % lineBuffer.length;
      break;
      }
      if (ch == '\b')
      {
      if (lineBufferHead == lineBufferTail)
      {
          consoleCanvas.invertScreen ();
      }
      else
      {
          int chToErase;
  
          lineBufferHead = (lineBufferHead + lineBuffer.length - 1) % lineBuffer.length;
          chToErase = lineBuffer [lineBufferHead];
          if (echoOn)
          {
          if (chToErase != '\t')
          {
              erasePreviousChar ();
          }
          else
          {
              int cnt;
              eraseLineOfInput ();
              cnt = lineBufferTail;
              while (cnt != lineBufferHead)
              {
              print (lineBuffer [cnt]);
              cnt = (cnt + 1) % lineBuffer.length;
              }
          }
          }
      }
      } // if backspace
      else if (ch == '\025')
      {
      if (echoOn)
      {
          eraseLineOfInput ();
      }
      lineBufferHead = lineBufferTail;
      }
      else
      {
      if (echoOn)
      {
          print (ch);
      }
      lineBuffer [lineBufferHead] = ch;
      lineBufferHead = (lineBufferHead + 1) % lineBuffer.length;
      }
  } // while
  
  result = lineBuffer [lineBufferTail];
  lineBufferTail = (lineBufferTail + 1) % lineBuffer.length;
  
  // Turn cursor on if necessary
  consoleCanvas.setCursorVisible (false);
  
  return (result);
  }
  </code></pre>