title: How to print even and odd position characters of an array of strings in Java?
body: <p><strong>Question</strong></p>
  
  <blockquote>
    <p><em>Given a string S of length N, that is indexed from 0 to N-1, print it's even indexed and odd indexed characters as 2 space separated strings on a single line.
    Assume input starts at index position 0(which is considered even)</em></p>
  </blockquote>
  
  <p><strong>Input</strong></p>
  
  <blockquote>
    <p><em>The first line contains an integer, T (the number of test cases). 
    Each line i of the T subsequent lines contain a String, S.</em></p>
  </blockquote>
  
  <p><strong>Output</strong></p>
  
  <blockquote>
    <p><em>For each string S, print it's even-indexed characters, followed by space, followed by odd-indexed characters.</em> </p>
  </blockquote>
  
  <p><strong>Sample Input</strong></p>
  
  <blockquote>
    <p>2</p>
    
    <p>Hacker</p>
    
    <p>Rank</p>
  </blockquote>
  
  <p><strong>Sample Output</strong></p>
  
  <blockquote>
    <p>Hce akr</p>
    
    <p>Rn ak</p>
  </blockquote>
  
  <p><strong>The Code I Wrote</strong></p>
  
  <pre><code>public static void main(String[] args)
  {
      Scanner scan    =   new Scanner(System.in);
      int T   =   scan.nextInt();
      scan.nextLine();
  
      for(int i=0 ; i&lt;T ; i++)
      {
          String  myString    =   scan.nextLine();
  
          int evn =   0,
              odd =   0,
              len =   myString.length();
  
          char    strE[]  =   new char[50],
                  strO[]  =   new char[50];
  
          for(int j=0 ; j&lt;len ; j++)
          {
              if(j%2 == 0)
              {
                  strE[evn]   =   myString.charAt(j);
                  evn++;
              }
              if(j%2 == 1)
              {
                  strO[odd]   =   myString.charAt(j);
                  odd++;
              }
          }
          System.out.print(strE);
          System.out.print(" ");
          System.out.println(strO);
      }
  }
  </code></pre>
  
  <p><strong>My Output</strong></p>
  
  <blockquote>
    <p>Hce akr</p>
    
    <p>Rn ak</p>
  </blockquote>
  
  <p><strong>The Problem</strong></p>
  
  <blockquote>
    <p><em>As you can see, my program successfully meets the test case, and other test cases (using custom input) but every time the HackerRank compiler tells me that my program did not meet the test case.</em></p>
    
    <p><em>Clearly, my program is producing the required output but every time the HackerRank compiler tells me that I got the solution wrong.</em></p>
    
    <p><strong>Could anyone please tell me where I am making a mistake?</strong></p>
  </blockquote>
  
  <p><strong>Further Modifications</strong></p>
  
  <blockquote>
    <p><em>I then decided to change the last 3 lines of print statements into one statement as follows:</em></p>
  </blockquote>
  
  <pre><code>System.out.println(strE + " " + strO);
  </code></pre>
  
  <blockquote>
    <p><em>However, this time the program <strong>did not</strong> produce the desired output and rather printed some garbage values as follows:</em></p>
    
    <p>[C@5c3f3b9b [C@3b626c6d</p>
    
    <p>[C@3abc8690 [C@2f267610</p>
  </blockquote>
  
  <p><strong>My Doubts</strong></p>
  
  <blockquote>
    <p><em>1. In the first case, when I was printing the two strings separately using 2 print statements, I was getting a correct output everytime but the HackerRank compiler rejected it. <strong>Why?</em></strong></p>
    
    <p><em>2. In the second case, when I modified the program by using one print statement instead of 3 to get the desired result, the program gave a completely different output and rather printed garbage values! <strong>Why?</em></strong></p>
  </blockquote>
  
  <p><em>Here is a link to the HackerRank problem for more info:</em>
  <a href="https://www.hackerrank.com/challenges/30-review-loop" rel="nofollow noreferrer">hackerrank.com/challenges/30-review-loop</a></p>
  
  <p><em>All help and guidance is greatly appreciated and thanks a lot in advance!</em></p>