title: Java Concatenating two Strings with only charAt
body: <p>Our task was write a code to concatenate two strings with only using charAt. So what I did was the following:</p>
  
  <pre><code>Scanner sc = new Scanner (System.in);
  char operation = sc.nextLine().charAt(0)
  String c = "concatenation";
  if (operation == 'c' ) {
          System.out.println("Please enter the first string: ");
          String firstString = sc.next();
          System.out.println("Please enter the scond string: ");
          String secondString = sc.next();
  
          System.out.print("The result of concatenating " + firstString + " and " + secondString + " is ");
          for (int i = 0; i &lt; firstString.length(); i++) {
              char x = firstString.charAt(i);
              System.out.print(x);
          }
          for (int i = 0; i &lt; secondString.length(); i++) {
              char y = secondString.charAt(i);
              System.out.print(y);
          }
      }
  </code></pre>
  
  <p>My teacher told me the following: "So currently you are simply printing, but the goal is to create a new string, which is the concatenation of both s1 and s2… then you print the new string you created. So using charAt is the way to go, but instead of printing one char at a time, you need to concatenate one char at a time." </p>
  
  <p>So I thought maybe something like this could work:</p>
  
  <pre><code>String concatenated;
      for (int i = 0; i &lt; firstString.length(); i++){
          concatenated = firstString.charAt(i);
      }
  </code></pre>
  
  <p>Apparently that was not the case, because of incompatible types.</p>
  
  <p>So I wanted to ask you what I could possibly do, to concatenate two strings with only using charAt. </p>