forked from Shreerang4/learning-basics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringtokenizer_basics.java
More file actions
21 lines (20 loc) · 884 Bytes
/
stringtokenizer_basics.java
File metadata and controls
21 lines (20 loc) · 884 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import java.util.*;
public class stringtokenizer_basics {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Please enter a punctuated paragraph: ");
String s=sc.nextLine();
System.out.println("Sentences of the paragraph are: \n");
StringTokenizer st=new StringTokenizer(s,"?!.");//First parameter is the string you want to filter through
while (st.hasMoreTokens()){//and second parameter is the delimiters. A token is a string between two consecutive
String tok=st.nextToken(); //delimiters. If 2nd parameter is left blank, space is the default delimiter.
System.out.println(tok);
}
}
}
//SAMPLE I/O : Pleas enter a punctuated paragraph:
//I am X. I am a good boy! Am I not?
//Sentences of the paragraph are:
//I am X
// I am a good boy
// Am I not