-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathString_Tokens.java
More file actions
24 lines (22 loc) · 791 Bytes
/
String_Tokens.java
File metadata and controls
24 lines (22 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String s = scan.nextLine();
// Write your code here.
s = s.trim();//if there is any trailing spaces..
if(s.length()==0) //if the string is zero
{
System.out.println(0); //number of tokens will be zero..
return; //return nothing..
}
String C[] = s.split("[^A-Za-z]+"); //split it if any non alphabetical characters are found..
System.out.println(C.length); //printing the number of tokens...
for(int i=0;i<C.length;i++)
{
System.out.println(C[i]); //printing the tokens..
}
scan.close();
}
}