Hello StackOverflow peeps!
Working to learn/improve my coding skills with hackerrank.com's 30 days of code. I'm on day 6 and having some issues figuring out why I'm getting this error message:
"~ no response on stdout ~"
I've done some searching on google and within stackoverflow and found others with the same error but it was because they weren't using standard I/O. I feel like I am, what am I missing?
Here's my code:
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc = new Scanner(System.in);
int cases = sc.nextInt();
while(cases > 0){
getWord();
cases--;
}
}
public static void getWord(){
//Save input to string
Scanner sc = new Scanner(System.in);
String userInput = sc.nextLine();
//Convert string to character array
char[] inputCharArray = userInput.toCharArray();
//Setup output strings
String evenOutputString = "";
String oddOutputString = "";
//Iterate through array
for (int i = 0; i <= userInput.length(); i++) {
//Check if index is even
if (i % 2 == 0) {
//Add to even output string
evenOutputString = evenOutputString + inputCharArray[i];
} else {
//Add to odd output string
oddOutputString = oddOutputString + inputCharArray[i];
}
}
//Output final output in one line, seperated by a single space
System.out.println(evenOutputString + " " + oddOutputString);
}
}
The challenge can be found here: https://www.hackerrank.com/challenges/30-review-loop/problem
The first input is a number that determines how many test cases will occur, the following inputs are single words that I'm supposed to put into an array and then sort out the even and odd index slots and print them on one line, separated by a space.
Example Input:
2
Hacker
Rank
Example Output:
Hce akr
Rn ak
I've tried moving the while(cases > 0) code block to it's own method just in case the args from the main method was part of the problem, and got the same results. I've also tried the .toString on the inputCharArray[i] for the output string concatenation. I'm also trying to stay away from StringBuilder so that I can stay within the intended scope of the challenge.