-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaStringTokens.java
More file actions
41 lines (34 loc) · 947 Bytes
/
JavaStringTokens.java
File metadata and controls
41 lines (34 loc) · 947 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.io.*;
import java.util.*;
public class JavaStringTokens {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
int l =s.length();
int i,c=0,t=0;
String[] str= new String[l+1];
String s1=new String();
char ch;
for(i=0;i<l;i++){
ch=s.charAt(i);
if(ch=='?'||ch==' '||ch=='\''||ch==','||ch=='_'||ch=='@'||ch=='.'||ch=='!'){
if(s1!=""){
c++;
str[i]=s1;
}
s1="";
}
else{
s1=s1+ch;
}
t++;
}
str[t]=s1;
System.out.println(c);
for(i=0;i<str.length;i++){
if(str[i]!=null)
System.out.println(str[i]);
}
sc.close();
}
}