Day 6: Let's Review Hackerrank Solution Java
For Explanation Check The Video:
Sample Input
2
Hacker
Rank
Sample Output
Hce akr
Rn ak
Code:
import java.io.*;import java.util.*;
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 scn = new Scanner(System.in); int t = scn.nextInt(); for(int i=0;i<t;i++){ String s = scn.next();//Rank String s_even = ""; String s_odd = ""; for(int j=0;j<s.length();j++){ if(j%2==0){ s_even = s_even + s.charAt(j);//Rn }else{ s_odd = s_odd + s.charAt(j);//ak } } System.out.println(s_even+" "+s_odd); } }}
Comments
Post a Comment