forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlphabetical.java
More file actions
20 lines (18 loc) · 548 Bytes
/
Alphabetical.java
File metadata and controls
20 lines (18 loc) · 548 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package com.string;
public class Alphabetical {
/**
* 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;
}
}