title: How to use for to iterate inside a String replace every char (A with T, T, with A, G with C, C with G)?
body: <p>I'm new at coding. And I'm doing an exercise, where I create a random ADN this n length (the one the user inputs). This this, I have to generate a new complementary adn.</p>
  <p>The principal ADN uses just = A, C, G, T. In my new complementary ADN, I have to change every char, because 'A' needs to be replaced with 'T',every 'T' needs to be replaced this 'A', every 'G' has to ve replaced with 'C', and every 'C' need to be replaced with 'G'.</p>
  <p>Example:</p>
  <p>My random ADN would be = ACCGTTTTAAG. My new complementary ADN would be = TGGCAAAATTC.</p>
  <p>This is my code where I'm trying to use a for to iterate inside my string and to replace the letters. No success though. But I think I have the idea. How can I proceed?</p>
  <pre><code>public String cadenaComplementaria(String ADN) {
  this.ADN = ADN;
  String ADNComplementario = &quot;&quot;;
  
  for (int i = 0; i &lt;= ADN.length(); i++) {
  
      if(this.ADN.charAt(i)=='A'){
          this.ADN.replace('A','T');
          ADNComplementario = this.ADN;
      }
      else if(this.ADN.charAt(i)=='C'){
          this.ADN.replace('C', 'G');
      }
      else if(this.ADN.charAt(i)=='G'){
          this.ADN.replace('G','C');
      }
      else if (this.ADN.charAt(i)=='T'){
          this.ADN.replace('T','A');
      }
  return ADNComplementario;
  }
  </code></pre>
  <p>So I'm trying to use a for to iterate inside my string, I'm trying to read what char is in the position so it can be replaced, it's not working though. I was trying to transfer the ADN value to the ADNComplementario to call it in my main, maybe I'm doing it wrong.</p>
  <p>As you can see its a function, I'm learning programming oriented to object.</p>