Hackerrank – Java Solution – Java String Tokens solution

Hackerrank - Java Solutions Hackerrank Online Judge Solution

Hackerrank – Java Solution – Java String Tokens

Problem Name – Java String Tokens
Problem Link –  Java String Tokens
Level – String
Point – 15

Java Code

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();

s = s.trim(); // so that .split() works properly

/* 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);
}
}
}

Output: 

Hackerrank - Java Solution - Java String Tokens solution

Tags: HackerRank Online Judge Solution, HackerRank OJ Solution list, HackerRank Problems Solution, HackerRank solver, HackerRank all problem solution list, HackerRank solution in java, Hackerrank Java Solution, Hackerrank – Java Solution – Java String Tokens, Hackerrank Online Judge Solution, Hackerrank – Java Solutions,

Leave a Reply

Your email address will not be published.