title: How to replace odd/even chars in string with spaces in Java?
body: <p>If given a string like "go to med!" how do I replace just the even characters for example? The problem is that while my code takes care of the first word, the space between the words counts as a character itself and messes up replacements in the second word with the first letter of the second word becoming classified as even.</p>
  
  <p>Here is my attempt</p>
  
  <pre><code>public static void main(String[] args) {
      String s = "go to med!";
      String alphabetS = "abcdefghijklmnopqrstuvwxyz";
      StringBuilder sb = new StringBuilder(s);
  
      for(int i=0; i&lt;s.length(); i++){
          char currChar = s.charAt(i);
  
          int idx = alphabetS.indexOf(currChar);
          if (idx != -1) 
          if (i%2==1)
  
              {
          sb.setCharAt(i, '*');
          }
  
      }
      System.out.println(sb);
  
  }
  </code></pre>
  
  <p>This gives output "g+ +o m+d!" 
  (second letter being correctly replaced by + for being even, but the first letter of the second word should not be replaced as "first" is not "even". 
  How to make the index to ignore white spaces?</p>
  
  <p>Preferably the answer should not contain arrays, only Char and String methods.</p>