Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4591884

Browse files
Merge pull requestTheAlgorithms#1925 from JackZeled0n/Development
Incorporate the class Alphabetical from string package
2 parents56a611a +f4f0dfd commit4591884

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
packagecom.string;
2+
3+
publicclassAlphabetical {
4+
5+
/**
6+
* Check if a string is alphabetical order or not
7+
*
8+
* @param s a string
9+
* @return {@code true} if given string is alphabetical order, otherwise {@code false}
10+
*/
11+
publicstaticbooleanisAlphabetical(Strings) {
12+
s =s.toLowerCase();
13+
for (inti =0;i <s.length() -1; ++i) {
14+
if (!Character.isLetter(s.charAt(i)) || !(s.charAt(i) <=s.charAt(i +1))) {
15+
returnfalse;
16+
}
17+
}
18+
returntrue;
19+
}
20+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
packagecom.string;
2+
3+
importorg.junit.jupiter.api.Assertions;
4+
importorg.junit.jupiter.api.Test;
5+
6+
classAlphabeticalTestextendsAlphabetical {
7+
8+
@Test
9+
voidtestAlphabetical() {
10+
Assertions.assertEquals(true,isAlphabetical("abc"),"The string is in order");
11+
Assertions.assertEquals(false,isAlphabetical("testing"),"The string is not in order");
12+
}
13+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp