Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions app/src/main/java/strings/Strops.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

public class Strops {
/**
* Reverses a string
* Reverses a string.
*
* @param str The string to reverse.
* @param str The string to reverse. Must not be null.
* @return The reversed string.
* @throws IllegalArgumentException if {@code str} is null.
*/
public String reverse(String str) {
if (str == null) {
throw new IllegalArgumentException("Input string must not be null");
}
StringBuilder reversed = new StringBuilder();
for (int i = str.length() - 1; i >= 0; i--) {
reversed.append(str.charAt(i));
Expand All @@ -16,12 +20,16 @@ public String reverse(String str) {
}

/**
* Checks if a string is a palindrome
* Checks if a string is a palindrome.
*
* @param str The string to check.
* @return True if the string is a palindrome, false otherwise.
* @param str The string to check. Must not be null.
* @return True if the string is a palindrome, false otherwise. Returns false for empty strings.
* @throws IllegalArgumentException if {@code str} is null.
*/
public boolean isPalindrome(String str) {
if (str == null) {
throw new IllegalArgumentException("Input string must not be null");
}
if (str.length() == 0) {
return false;
}
Expand Down