FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaAlgorithms/strings/Alphabetical.java at main · sarvex/JavaAlgorithms · GitHub
sarvex
/
JavaAlgorithms
Public
forked from
TheAlgorithms/Java
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaAlgorithms
/
strings
/
Alphabetical.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
33 lines (30 loc) · 954 Bytes
Breadcrumbs
JavaAlgorithms
/
strings
/
Alphabetical.java
Copy path
File metadata and controls
33 lines (30 loc) · 954 Bytes
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
package
strings
;
/**
* Alphabetical order is a system whereby character strings are placed in order based on the
* position of the characters in the conventional ordering of an alphabet. Wikipedia:
* https://en.wikipedia.org/wiki/Alphabetical_order
*/
class
Alphabetical
{
public
static
void
main
(
String
[]
args
) {
assert
!
isAlphabetical
(
"123abc"
);
assert
isAlphabetical
(
"aBC"
);
assert
isAlphabetical
(
"abc"
);
assert
!
isAlphabetical
(
"xyzabc"
);
assert
isAlphabetical
(
"abcxyz"
);
}
/**
* Check if a string is alphabetical order or not
*
* @param s a string
* @return {@code true} if given string is alphabetical order, otherwise {@code false}
*/
public
static
boolean
isAlphabetical
(
String
s
) {
s
=
s
.
toLowerCase
();
for
(
int
i
=
0
;
i
<
s
.
length
() -
1
; ++
i
) {
if
(!
Character
.
isLetter
(
s
.
charAt
(
i
)) || !(
s
.
charAt
(
i
) <=
s
.
charAt
(
i
+
1
))) {
return
false
;
}
}
return
true
;
}
}
Back
|
FazBrowse Home
|
New Git URL