Created
June 18, 2016 08:02
-
-
Save abdulateef/28fe9681f92ada7c5012cd5402487f5d to your computer and use it in GitHub Desktop.
Given a string,S , of length that is indexed from 0 to N-1 , print its even-indexed and odd-indexed characters as space-separated strings on a single line . Note:0 is considered to be an even index.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Day6{ | |
public static void main(String[] args){ | |
Scanner input = new Scanner(System.in); | |
int n = input.nextInt(); | |
input.nextLine(); | |
String[] words = new String[n]; | |
StringBuffer even = new StringBuffer(); | |
StringBuffer odd = new StringBuffer(); | |
for (int i=0; i<n; i++){ | |
words[i] = input.nextLine(); | |
for (int j=0; j<words[i].length(); j++){ | |
if (j%2==0){ | |
even.append(words[i].charAt(j)); | |
}else { | |
odd.append(words[i].charAt(j)); | |
} | |
} | |
System.out.println(even+" "+odd); | |
even.delete(0,even.length()); | |
odd.delete(0, odd.length()); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment