static boolean allCharactersSame(String s){
int n = s.length();
for (int i = 1; i < n; i++)
if (s.charAt(i) != s.charAt(0))
return false;
return true;
}
To check if all characters are same
The function allCharactersSame() checks if the strings s and s are the same by comparing their characters.
0 Comments
Add Comment
Log in to add a comment