Skip to content

Commit d725780

Browse files
authored
Create EvenOddString.java
1 parent ef9cc64 commit d725780

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
// Input example as below.
5+
/*
6+
2
7+
Hacker
8+
Rank
9+
*/
10+
// Output as below.
11+
/*
12+
Hce akr
13+
Rn ak
14+
*/
15+
16+
17+
public class Solution {
18+
19+
public static void main(String[] args) {
20+
Scanner sc = new Scanner(System.in);
21+
int i = sc.nextInt();
22+
23+
if(i >= 1 && i <= 10){
24+
while(sc.hasNextLine()){
25+
String S = sc.nextLine();
26+
char[] ch = S.toCharArray();
27+
if(ch.length >= 2 && ch.length <= 10000)
28+
System.out.println(get(S));
29+
}
30+
}
31+
}
32+
33+
public static String get(String S) {
34+
StringBuilder a = new StringBuilder();
35+
StringBuilder b = new StringBuilder();
36+
char[] ch = S.toCharArray();
37+
for(int j = 0; j < ch.length; j++) {
38+
if(j == 0)
39+
a.append(ch[j]);
40+
else if(j%2 == 0)
41+
a.append(ch[j]);
42+
else
43+
b.append(ch[j]);
44+
}
45+
return a+" "+b;
46+
}
47+
}

0 commit comments

Comments
 (0)