-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay6
More file actions
32 lines (26 loc) · 948 Bytes
/
Day6
File metadata and controls
32 lines (26 loc) · 948 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Given a string,S, of length N that is indexed from 0 to N-1, print its even-indexed and odd-indexed characters as 2 space-separated strings on a single line
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) {
Scanner scan = new Scanner(System.in);
int testCases = scan.nextInt();
for(int i = 0; i < testCases; i++){
char[] inputString = scan.next().toCharArray();
// Print even chars
for(int j = 0; j < inputString.length; j += 2){
System.out.print(inputString[j]);
}
System.out.print(" ");
// Print odd chars
for(int j = 1; j < inputString.length; j += 2){
System.out.print(inputString[j]);
}
System.out.println();
}
scan.close();
}
}