-
Notifications
You must be signed in to change notification settings - Fork 0
/
split_strings.java
57 lines (49 loc) · 1.29 KB
/
split_strings.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//{ Driver Code Starts
//Initial Template for Java
import java.io.*;
import java.util.*;
class GFG{
public static void main(String args[]) throws IOException {
Scanner sc = new Scanner(System.in);
int t = Integer.parseInt(sc.nextLine());
while(t-- > 0){
String S = sc.nextLine();
Solution ob = new Solution();
List<String> ans = ob.splitString(S);
for (String val: ans)
if(val == "")
System.out.println(-1);
else
System.out.println(val);
}
}
}
// } Driver Code Ends
//User function Template for Java
class Solution
{
static List<String> splitString(String S)
{
// code here
ArrayList<String> arrs = new ArrayList<>();
String s1="";
String s2="";
String s3="";
for(int i=0; i<S.length() ; i++){
char ch = S.charAt(i);
if((ch>='a' && ch<='z')||(ch>='A' && ch<='Z')){
s1 = s1 + ch;
}
else if(ch>='0' && ch<='9'){
s2 = s2 +ch;
}
else{
s3 = s3 + ch;
}
}
arrs.add(s1);
arrs.add(s2);
arrs.add(s3);
return arrs;
}
}