title: How to make alternate characters in a string to uppercase?
body: <p>I wrote the following code but similar characters are always in the same case. What's wrong in this code and How can this problem be solved?? </p>
  
  <pre><code>private void genBTActionPerformed(java.awt.event.ActionEvent evt) {                                      
      String str = new String(strTF.getText());
      int n = str.length();
      char ch;
      int i;
      for(i = 0; i &lt; n; i++) {
          if(i % 2 == 0) {
              ch = Character.toLowerCase(str.charAt(i));
              str = str.replace(str.charAt(i), ch);
          } else {
              ch = Character.toUpperCase(str.charAt(i));
              str = str.replace(str.charAt(i), ch);
          }
      }
      jumTF.setText(str);
  }   
  </code></pre>