FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaProb/StringTokens.java at main · Warlord27/JavaProb · GitHub
Warlord27
/
JavaProb
Public
Notifications
You must be signed in to change notification settings
Fork
9
Star
13
Code
Issues
0
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaProb
/
StringTokens.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
42 lines (34 loc) · 1.07 KB
Breadcrumbs
JavaProb
/
StringTokens.java
Copy path
File metadata and controls
42 lines (34 loc) · 1.07 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
java
.
io
.*;
import
java
.
util
.*;
public
class
StringTokens
{
public
static
void
main
(
String
[]
args
) {
Scanner
scan
=
new
Scanner
(
System
.
in
);
System
.
out
.
println
(
"Enter: "
);
String
s
=
scan
.
nextLine
();
// Trim leading/trailing whitespace
s
=
s
.
trim
();
// Check if the string is empty after trimming
if
(
s
.
isEmpty
()) {
System
.
out
.
println
(
0
);
scan
.
close
();
return
;
}
// Split the string by one or more non-alphabetic characters
String
[]
tokens
=
s
.
split
(
"[^a-zA-Z]+"
);
// Count and print valid tokens (non-empty strings)
int
count
=
0
;
for
(
String
token
:
tokens
) {
if
(!
token
.
isEmpty
()) {
count
++;
}
}
System
.
out
.
println
(
count
);
// Print each valid token
for
(
String
token
:
tokens
) {
if
(!
token
.
isEmpty
()) {
System
.
out
.
println
(
token
);
}
}
scan
.
close
();
}
}
Back
|
FazBrowse Home
|
New Git URL