* Lower.java

* Upper.java
* Pangram.java
* CharactersSame.java
* CheckAnagrams.java
This commit is contained in:
shellhub
2020-08-27 00:01:50 +08:00
parent 19176d9ede
commit 0f4905d1d9
5 changed files with 160 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
package strings;
public class CharactersSame {
/**
* Driver Code
*/
public static void main(String[] args) {
assert isAllCharactersSame("");
assert !isAllCharactersSame("aab");
assert isAllCharactersSame("aaa");
assert isAllCharactersSame("11111");
}
/**
* check if all the characters of a string are same
*
* @param s the string to check
* @return {@code true} if all characters of a string are same, otherwise {@code false}
*/
public static boolean isAllCharactersSame(String s) {
for (int i = 1, length = s.length(); i < length; ++i) {
if (s.charAt(i) != s.charAt(0)) {
return false;
}
}
return true;
}
}