You are viewing a single comment's thread. Return to all comments →
Solution in Java with StringBuilder:
public class Solution { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int length = scanner.nextInt(); scanner.nextLine(); for (int i = 0; i < length; i++) { String inputString = scanner.nextLine(); StringBuilder even = new StringBuilder(); StringBuilder odd = new StringBuilder(); for (int j = 0; j < inputString.length(); j++) { if (j % 2 == 0) { even.append(inputString.charAt(j)); } else { odd.append(inputString.charAt(j)); } } System.out.println(even.toString() + " " + odd.toString()); } scanner.close(); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Day 6: Let's Review
You are viewing a single comment's thread. Return to all comments →
Solution in Java with StringBuilder: