You are viewing a single comment's thread. Return to all comments →
Interesting approach using streams in Java:
import java.io.; import java.util.; import java.util.stream.IntStream; import java.util.stream.Collectors;
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 test = sc.nextInt(); while(test > 0 ) { String text = sc.next(); String evenString = IntStream.range(0, text.length()) .filter(i -> i%2==0) .mapToObj(i -> String.valueOf(text.charAt(i))) .collect(Collectors.joining()); String oddString = IntStream.range(0, text.length()) .filter(i -> i%2 != 0) .mapToObj(i -> String.valueOf(text.charAt(i))) .collect(Collectors.joining()); System.out.println(evenString +" " + oddString); test--; } sc.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 →
Interesting approach using streams in Java:
import java.io.; import java.util.; import java.util.stream.IntStream; import java.util.stream.Collectors;
public class Solution {
}