forked from infiniteoverflow/VTU-DAA-LAB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStringTokeniser.java
39 lines (32 loc) · 1.07 KB
/
StringTokeniser.java
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
package com.programs;
import java.util.Scanner;
import java.util.StringTokenizer;
public class StringTokeniser {
String name;
public void readCustomer() {
Scanner in = new Scanner(System.in);
System.out.println("Enter the details in the format <name,dd/mm/yyyy");
name = in.nextLine();
if(!name.startsWith("<") && !name.endsWith(">")) {
System.out.println("Enter the name in the correct format");
return;
}
}
public void displayCustomer() {
StringTokenizer token = new StringTokenizer(name,"<,/>");
String finalString = null;
while(token.hasMoreTokens()) {
if(finalString==null) {
finalString = token.nextToken();
}
else
finalString = finalString + " "+token.nextToken();
}
System.out.println("The final String is :"+finalString);
}
public static void main(String[] args) {
StringTokeniser st = new StringTokeniser();
st.readCustomer();
st.displayCustomer();
}
}