Files
HackerRank-Solutions/Java/Strings/Java String Tokens/Solution.java
T

33 lines
824 B
Java
Raw Normal View History

2017-02-12 00:31:12 -08:00
// Author: Rodney Shaghoulian
// Github: github.com/rshaghoulian
// HackerRank: hackerrank.com/rshaghoulian
2017-02-09 02:12:38 -08:00
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
/* Read input */
Scanner scan = new Scanner(System.in);
String s = scan.nextLine();
scan.close();
2017-02-12 00:31:12 -08:00
s = s.trim(); // needed to pass test cases
2017-02-09 02:12:38 -08:00
/* Check special cases */
if (s.length() == 0) {
System.out.println(0);
return;
}
/* Split on all non-alphabetic characters */
String [] words = s.split("[^a-zA-Z]+");
/* Print output */
System.out.println(words.length);
for (String word : words) {
System.out.println(word);
}
}
}